diff --git a/units/src/amount/signed.rs b/units/src/amount/signed.rs index 82a07fa05..aece125bd 100644 --- a/units/src/amount/signed.rs +++ b/units/src/amount/signed.rs @@ -109,7 +109,7 @@ impl SignedAmount { /// ``` #[cfg(feature = "alloc")] pub fn from_btc(btc: f64) -> Result { - SignedAmount::from_float_in(btc, Denomination::Bitcoin) + Self::from_float_in(btc, Denomination::Bitcoin) } /// Converts from a value expressing a whole number of bitcoin to a [`SignedAmount`]. @@ -120,7 +120,7 @@ impl SignedAmount { /// per bitcoin overflows an `i64` type. pub fn from_int_btc>(whole_bitcoin: T) -> Result { match whole_bitcoin.into().checked_mul(100_000_000) { - Some(amount) => Ok(SignedAmount::from_sat(amount)), + Some(amount) => Ok(Self::from_sat(amount)), None => Err(OutOfRangeError { is_signed: true, is_greater_than_max: true }), } } @@ -180,7 +180,7 @@ impl SignedAmount { /// ``` pub fn from_str_with_denomination(s: &str) -> Result { let (amt, denom) = split_amount_and_denomination(s)?; - SignedAmount::from_str_in(amt, denom).map_err(Into::into) + Self::from_str_in(amt, denom).map_err(Into::into) } /// Expresses this [`SignedAmount`] as a floating-point value in the given [`Denomination`]. @@ -228,7 +228,7 @@ impl SignedAmount { ) -> Result { // This is inefficient, but the safest way to deal with this. The parsing logic is safe. // Any performance-critical application should not be dealing with floats. - SignedAmount::from_str_in(&value.to_string(), denom) + Self::from_str_in(&value.to_string(), denom) } /// Constructs a new object that implements [`fmt::Display`] in the given [`Denomination`]. @@ -548,14 +548,14 @@ impl FromStr for SignedAmount { /// /// If the returned value would be zero or negative zero, then no denomination is required. fn from_str(s: &str) -> Result { - let result = SignedAmount::from_str_with_denomination(s); + let result = Self::from_str_with_denomination(s); match result { Err(ParseError(ParseErrorInner::MissingDenomination(_))) => { - let d = SignedAmount::from_str_in(s, Denomination::Satoshi); + let d = Self::from_str_in(s, Denomination::Satoshi); - if d == Ok(SignedAmount::ZERO) { - Ok(SignedAmount::ZERO) + if d == Ok(Self::ZERO) { + Ok(Self::ZERO) } else { result } @@ -568,14 +568,14 @@ impl FromStr for SignedAmount { impl From for SignedAmount { fn from(value: Amount) -> Self { let v = value.to_sat() as i64; // Cast ok, signed amount and amount share positive range. - SignedAmount::from_sat_unchecked(v) + Self::from_sat_unchecked(v) } } impl core::iter::Sum for SignedAmount { fn sum>(iter: I) -> Self { let sats: i64 = iter.map(|amt| amt.0).sum(); - SignedAmount::from_sat(sats) + Self::from_sat(sats) } } @@ -585,7 +585,7 @@ impl<'a> core::iter::Sum<&'a SignedAmount> for SignedAmount { I: Iterator, { let sats: i64 = iter.map(|amt| amt.0).sum(); - SignedAmount::from_sat(sats) + Self::from_sat(sats) } } @@ -593,6 +593,6 @@ impl<'a> core::iter::Sum<&'a SignedAmount> for SignedAmount { impl<'a> Arbitrary<'a> for SignedAmount { fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { let s = i64::arbitrary(u)?; - Ok(SignedAmount(s)) + Ok(Self(s)) } } diff --git a/units/src/amount/unsigned.rs b/units/src/amount/unsigned.rs index 0cc4a4356..e80f5c6b7 100644 --- a/units/src/amount/unsigned.rs +++ b/units/src/amount/unsigned.rs @@ -112,7 +112,7 @@ impl Amount { /// ``` #[cfg(feature = "alloc")] pub fn from_btc(btc: f64) -> Result { - Amount::from_float_in(btc, Denomination::Bitcoin) + Self::from_float_in(btc, Denomination::Bitcoin) } /// Converts from a value expressing a whole number of bitcoin to an [`Amount`]. @@ -123,7 +123,7 @@ impl Amount { /// per bitcoin overflows a `u64` type. pub fn from_int_btc>(whole_bitcoin: T) -> Result { match whole_bitcoin.into().checked_mul(100_000_000) { - Some(amount) => Ok(Amount::from_sat(amount)), + Some(amount) => Ok(Self::from_sat(amount)), None => Err(OutOfRangeError { is_signed: false, is_greater_than_max: true }), } } @@ -164,7 +164,7 @@ impl Amount { OutOfRangeError::too_big(false), ))); } - Ok(Amount::from_sat(sats)) + Ok(Self::from_sat(sats)) } /// Parses amounts with denomination suffix as produced by [`Self::to_string_with_denomination`] @@ -186,7 +186,7 @@ impl Amount { /// ``` pub fn from_str_with_denomination(s: &str) -> Result { let (amt, denom) = split_amount_and_denomination(s)?; - Amount::from_str_in(amt, denom).map_err(Into::into) + Self::from_str_in(amt, denom).map_err(Into::into) } /// Expresses this [`Amount`] as a floating-point value in the given [`Denomination`]. @@ -234,7 +234,7 @@ impl Amount { } // This is inefficient, but the safest way to deal with this. The parsing logic is safe. // Any performance-critical application should not be dealing with floats. - Amount::from_str_in(&value.to_string(), denom) + Self::from_str_in(&value.to_string(), denom) } /// Constructs a new object that implements [`fmt::Display`] in the given [`Denomination`]. @@ -483,14 +483,14 @@ impl FromStr for Amount { /// /// If the returned value would be zero or negative zero, then no denomination is required. fn from_str(s: &str) -> Result { - let result = Amount::from_str_with_denomination(s); + let result = Self::from_str_with_denomination(s); match result { Err(ParseError(ParseErrorInner::MissingDenomination(_))) => { - let d = Amount::from_str_in(s, Denomination::Satoshi); + let d = Self::from_str_in(s, Denomination::Satoshi); - if d == Ok(Amount::ZERO) { - Ok(Amount::ZERO) + if d == Ok(Self::ZERO) { + Ok(Self::ZERO) } else { result } @@ -509,7 +509,7 @@ impl TryFrom for Amount { impl core::iter::Sum for Amount { fn sum>(iter: I) -> Self { let sats: u64 = iter.map(|amt| amt.0).sum(); - Amount::from_sat(sats) + Self::from_sat(sats) } } @@ -519,7 +519,7 @@ impl<'a> core::iter::Sum<&'a Amount> for Amount { I: Iterator, { let sats: u64 = iter.map(|amt| amt.0).sum(); - Amount::from_sat(sats) + Self::from_sat(sats) } } @@ -527,6 +527,6 @@ impl<'a> core::iter::Sum<&'a Amount> for Amount { impl<'a> Arbitrary<'a> for Amount { fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { let a = u64::arbitrary(u)?; - Ok(Amount(a)) + Ok(Self(a)) } }