@@ -61,8 +61,8 @@ mod encapsulate {
6161 ///
6262 /// Accepts an `i32` which is guaranteed to be in range for the type, but which can only
6363 /// represent roughly -21.47 to 21.47 BTC.
64- pub const fn from_sat_i32 ( satoshi : i32 ) -> SignedAmount {
65- SignedAmount ( satoshi as i64 ) // cannot use i64::from in a constfn
64+ pub const fn from_sat_i32 ( satoshi : i32 ) -> Self {
65+ Self ( satoshi as i64 ) // cannot use i64::from in a constfn
6666 }
6767
6868 /// Gets the number of satoshis in this [`SignedAmount`].
@@ -90,7 +90,7 @@ mod encapsulate {
9090 /// assert_eq!(amount.to_sat(), sat);
9191 /// # Ok::<_, amount::OutOfRangeError>(())
9292 /// ```
93- pub const fn from_sat ( satoshi : i64 ) -> Result < SignedAmount , OutOfRangeError > {
93+ pub const fn from_sat ( satoshi : i64 ) -> Result < Self , OutOfRangeError > {
9494 if satoshi < Self :: MIN . to_sat ( ) {
9595 Err ( OutOfRangeError { is_signed : true , is_greater_than_max : false } )
9696 } else if satoshi > Self :: MAX_MONEY . to_sat ( ) {
@@ -106,13 +106,13 @@ pub use encapsulate::SignedAmount;
106106
107107impl SignedAmount {
108108 /// The zero amount.
109- pub const ZERO : Self = SignedAmount :: from_sat_i32 ( 0 ) ;
109+ pub const ZERO : Self = Self :: from_sat_i32 ( 0 ) ;
110110 /// Exactly one satoshi.
111- pub const ONE_SAT : Self = SignedAmount :: from_sat_i32 ( 1 ) ;
111+ pub const ONE_SAT : Self = Self :: from_sat_i32 ( 1 ) ;
112112 /// Exactly one bitcoin.
113- pub const ONE_BTC : Self = SignedAmount :: from_btc_i16 ( 1 ) ;
113+ pub const ONE_BTC : Self = Self :: from_btc_i16 ( 1 ) ;
114114 /// Exactly fifty bitcoin.
115- pub const FIFTY_BTC : Self = SignedAmount :: from_btc_i16 ( 50 ) ;
115+ pub const FIFTY_BTC : Self = Self :: from_btc_i16 ( 50 ) ;
116116 /// The maximum value allowed as an amount. Useful for sanity checking.
117117 pub const MAX_MONEY : Self = Self :: MAX ;
118118
@@ -133,24 +133,24 @@ impl SignedAmount {
133133 /// # Ok::<_, amount::ParseAmountError>(())
134134 /// ```
135135 #[ cfg( feature = "alloc" ) ]
136- pub fn from_btc ( btc : f64 ) -> Result < SignedAmount , ParseAmountError > {
136+ pub fn from_btc ( btc : f64 ) -> Result < Self , ParseAmountError > {
137137 Self :: from_float_in ( btc, Denomination :: Bitcoin )
138138 }
139139
140140 /// Converts from a value expressing a whole number of bitcoin to a [`SignedAmount`].
141141 #[ allow( clippy:: missing_panics_doc) ]
142- pub fn from_int_btc < T : Into < i16 > > ( whole_bitcoin : T ) -> SignedAmount {
143- SignedAmount :: from_btc_i16 ( whole_bitcoin. into ( ) )
142+ pub fn from_int_btc < T : Into < i16 > > ( whole_bitcoin : T ) -> Self {
143+ Self :: from_btc_i16 ( whole_bitcoin. into ( ) )
144144 }
145145
146146 /// Converts from a value expressing a whole number of bitcoin to a [`SignedAmount`]
147147 /// in const context.
148148 #[ allow( clippy:: missing_panics_doc) ]
149- pub const fn from_btc_i16 ( whole_bitcoin : i16 ) -> SignedAmount {
149+ pub const fn from_btc_i16 ( whole_bitcoin : i16 ) -> Self {
150150 let btc = whole_bitcoin as i64 ; // Can't call `into` in const context.
151151 let sats = btc * 100_000_000 ;
152152
153- match SignedAmount :: from_sat ( sats) {
153+ match Self :: from_sat ( sats) {
154154 Ok ( amount) => amount,
155155 Err ( _) => panic ! ( "unreachable - 65536 BTC is within range" ) ,
156156 }
@@ -164,7 +164,7 @@ impl SignedAmount {
164164 /// # Errors
165165 ///
166166 /// If the amount is too big (positive or negative) or too precise.
167- pub fn from_str_in ( s : & str , denom : Denomination ) -> Result < SignedAmount , ParseAmountError > {
167+ pub fn from_str_in ( s : & str , denom : Denomination ) -> Result < Self , ParseAmountError > {
168168 parse_signed_to_satoshi ( s, denom)
169169 . map ( |( _, amount) | amount)
170170 . map_err ( |error| error. convert ( true ) )
@@ -187,7 +187,7 @@ impl SignedAmount {
187187 /// assert_eq!(amount, SignedAmount::from_sat(10_000_000)?);
188188 /// # Ok::<_, amount::ParseError>(())
189189 /// ```
190- pub fn from_str_with_denomination ( s : & str ) -> Result < SignedAmount , ParseError > {
190+ pub fn from_str_with_denomination ( s : & str ) -> Result < Self , ParseError > {
191191 let ( amt, denom) = split_amount_and_denomination ( s) ?;
192192 Self :: from_str_in ( amt, denom) . map_err ( Into :: into)
193193 }
@@ -236,7 +236,7 @@ impl SignedAmount {
236236 pub fn from_float_in (
237237 value : f64 ,
238238 denom : Denomination ,
239- ) -> Result < SignedAmount , ParseAmountError > {
239+ ) -> Result < Self , ParseAmountError > {
240240 // This is inefficient, but the safest way to deal with this. The parsing logic is safe.
241241 // Any performance-critical application should not be dealing with floats.
242242 Self :: from_str_in ( & value. to_string ( ) , denom)
@@ -315,7 +315,7 @@ impl SignedAmount {
315315 ///
316316 /// This function never overflows or panics, unlike `i64::abs()`.
317317 #[ must_use]
318- pub const fn abs ( self ) -> SignedAmount {
318+ pub const fn abs ( self ) -> Self {
319319 // `i64::abs()` can never overflow because SignedAmount::MIN == -MAX_MONEY.
320320 match Self :: from_sat ( self . to_sat ( ) . abs ( ) ) {
321321 Ok ( amount) => amount,
@@ -358,16 +358,16 @@ impl SignedAmount {
358358 #[ must_use]
359359 #[ deprecated( since = "TBD" , note = "Never returns none, use `abs()` instead" ) ]
360360 #[ allow( clippy:: unnecessary_wraps) ] // To match stdlib function definition.
361- pub const fn checked_abs ( self ) -> Option < SignedAmount > { Some ( self . abs ( ) ) }
361+ pub const fn checked_abs ( self ) -> Option < Self > { Some ( self . abs ( ) ) }
362362
363363 /// Checked addition.
364364 ///
365365 /// Returns [`None`] if the sum is above [`SignedAmount::MAX`] or below [`SignedAmount::MIN`].
366366 #[ must_use]
367- pub const fn checked_add ( self , rhs : SignedAmount ) -> Option < SignedAmount > {
367+ pub const fn checked_add ( self , rhs : Self ) -> Option < Self > {
368368 // No `map()` in const context.
369369 match self . to_sat ( ) . checked_add ( rhs. to_sat ( ) ) {
370- Some ( res) => match SignedAmount :: from_sat ( res) {
370+ Some ( res) => match Self :: from_sat ( res) {
371371 Ok ( amount) => Some ( amount) ,
372372 Err ( _) => None ,
373373 } ,
@@ -380,7 +380,7 @@ impl SignedAmount {
380380 /// Returns [`None`] if the difference is above [`SignedAmount::MAX`] or below
381381 /// [`SignedAmount::MIN`].
382382 #[ must_use]
383- pub const fn checked_sub ( self , rhs : SignedAmount ) -> Option < SignedAmount > {
383+ pub const fn checked_sub ( self , rhs : Self ) -> Option < Self > {
384384 // No `map()` in const context.
385385 match self . to_sat ( ) . checked_sub ( rhs. to_sat ( ) ) {
386386 Some ( res) => match Self :: from_sat ( res) {
@@ -396,7 +396,7 @@ impl SignedAmount {
396396 /// Returns [`None`] if the product is above [`SignedAmount::MAX`] or below
397397 /// [`SignedAmount::MIN`].
398398 #[ must_use]
399- pub const fn checked_mul ( self , rhs : i64 ) -> Option < SignedAmount > {
399+ pub const fn checked_mul ( self , rhs : i64 ) -> Option < Self > {
400400 // No `map()` in const context.
401401 match self . to_sat ( ) . checked_mul ( rhs) {
402402 Some ( res) => match Self :: from_sat ( res) {
@@ -413,7 +413,7 @@ impl SignedAmount {
413413 ///
414414 /// Returns [`None`] if overflow occurred.
415415 #[ must_use]
416- pub const fn checked_div ( self , rhs : i64 ) -> Option < SignedAmount > {
416+ pub const fn checked_div ( self , rhs : i64 ) -> Option < Self > {
417417 // No `map()` in const context.
418418 match self . to_sat ( ) . checked_div ( rhs) {
419419 Some ( res) => match Self :: from_sat ( res) {
@@ -428,7 +428,7 @@ impl SignedAmount {
428428 ///
429429 /// Returns [`None`] if overflow occurred.
430430 #[ must_use]
431- pub const fn checked_rem ( self , rhs : i64 ) -> Option < SignedAmount > {
431+ pub const fn checked_rem ( self , rhs : i64 ) -> Option < Self > {
432432 // No `map()` in const context.
433433 match self . to_sat ( ) . checked_rem ( rhs) {
434434 Some ( res) => match Self :: from_sat ( res) {
@@ -443,7 +443,7 @@ impl SignedAmount {
443443 ///
444444 /// Returns [`None`] if either `self`, `rhs` or the result is strictly negative.
445445 #[ must_use]
446- pub fn positive_sub ( self , rhs : SignedAmount ) -> Option < SignedAmount > {
446+ pub fn positive_sub ( self , rhs : Self ) -> Option < Self > {
447447 if self . is_negative ( ) || rhs. is_negative ( ) || rhs > self {
448448 None
449449 } else {
@@ -469,7 +469,7 @@ impl SignedAmount {
469469}
470470
471471impl default:: Default for SignedAmount {
472- fn default ( ) -> Self { SignedAmount :: ZERO }
472+ fn default ( ) -> Self { Self :: ZERO }
473473}
474474
475475impl fmt:: Debug for SignedAmount {
0 commit comments