@@ -170,6 +170,7 @@ impl Decimal256 {
170170 }
171171 }
172172
173+ #[ must_use]
173174 pub const fn is_zero ( & self ) -> bool {
174175 self . 0 . is_zero ( )
175176 }
@@ -192,6 +193,7 @@ impl Decimal256 {
192193 /// assert_eq!(b.decimal_places(), 18);
193194 /// assert_eq!(b.atomics(), Uint256::from(1u128));
194195 /// ```
196+ #[ must_use]
195197 #[ inline]
196198 pub const fn atomics ( & self ) -> Uint256 {
197199 self . 0
@@ -201,17 +203,20 @@ impl Decimal256 {
201203 /// but this could potentially change as the type evolves.
202204 ///
203205 /// See also [`Decimal256::atomics()`].
206+ #[ must_use]
204207 #[ inline]
205208 pub const fn decimal_places ( & self ) -> u32 {
206209 Self :: DECIMAL_PLACES
207210 }
208211
209212 /// Rounds value down after decimal places.
213+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
210214 pub fn floor ( & self ) -> Self {
211215 Self ( ( self . 0 / Self :: DECIMAL_FRACTIONAL ) * Self :: DECIMAL_FRACTIONAL )
212216 }
213217
214218 /// Rounds value up after decimal places. Panics on overflow.
219+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
215220 pub fn ceil ( & self ) -> Self {
216221 match self . checked_ceil ( ) {
217222 Ok ( value) => value,
@@ -260,6 +265,7 @@ impl Decimal256 {
260265 }
261266
262267 /// Raises a value to the power of `exp`, panics if an overflow occurred.
268+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
263269 pub fn pow ( self , exp : u32 ) -> Self {
264270 match self . checked_pow ( exp) {
265271 Ok ( value) => value,
@@ -314,6 +320,7 @@ impl Decimal256 {
314320 /// Returns the approximate square root as a Decimal256.
315321 ///
316322 /// This should not overflow or panic.
323+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
317324 pub fn sqrt ( & self ) -> Self {
318325 // Algorithm described in https://hackmd.io/@webmaster128/SJThlukj_
319326 // We start with the highest precision possible and lower it until
@@ -333,6 +340,7 @@ impl Decimal256 {
333340 /// Precision *must* be a number between 0 and 9 (inclusive).
334341 ///
335342 /// Returns `None` if the internal multiplication overflows.
343+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
336344 fn sqrt_with_precision ( & self , precision : u32 ) -> Option < Self > {
337345 let inner_mul = Uint256 :: from ( 100u128 ) . pow ( precision) ;
338346 self . 0 . checked_mul ( inner_mul) . ok ( ) . map ( |inner| {
@@ -341,6 +349,7 @@ impl Decimal256 {
341349 } )
342350 }
343351
352+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
344353 pub fn abs_diff ( self , other : Self ) -> Self {
345354 if self < other {
346355 other - self
@@ -349,27 +358,31 @@ impl Decimal256 {
349358 }
350359 }
351360
361+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
352362 pub fn saturating_add ( self , other : Self ) -> Self {
353363 match self . checked_add ( other) {
354364 Ok ( value) => value,
355365 Err ( _) => Self :: MAX ,
356366 }
357367 }
358368
369+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
359370 pub fn saturating_sub ( self , other : Self ) -> Self {
360371 match self . checked_sub ( other) {
361372 Ok ( value) => value,
362373 Err ( _) => Self :: zero ( ) ,
363374 }
364375 }
365376
377+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
366378 pub fn saturating_mul ( self , other : Self ) -> Self {
367379 match self . checked_mul ( other) {
368380 Ok ( value) => value,
369381 Err ( _) => Self :: MAX ,
370382 }
371383 }
372384
385+ #[ must_use = "this returns the result of the operation, without modifying the original" ]
373386 pub fn saturating_pow ( self , exp : u32 ) -> Self {
374387 match self . checked_pow ( exp) {
375388 Ok ( value) => value,
@@ -395,6 +408,7 @@ impl Decimal256 {
395408 /// let d = Decimal256::from_str("75.0").unwrap();
396409 /// assert_eq!(d.to_uint_floor(), Uint256::from(75u64));
397410 /// ```
411+ #[ must_use]
398412 pub fn to_uint_floor ( self ) -> Uint256 {
399413 self . 0 / Self :: DECIMAL_FRACTIONAL
400414 }
@@ -417,6 +431,7 @@ impl Decimal256 {
417431 /// let d = Decimal256::from_str("75.0").unwrap();
418432 /// assert_eq!(d.to_uint_ceil(), Uint256::from(75u64));
419433 /// ```
434+ #[ must_use]
420435 pub fn to_uint_ceil ( self ) -> Uint256 {
421436 // Using `q = 1 + ((x - 1) / y); // if x != 0` with unsigned integers x, y, q
422437 // from https://stackoverflow.com/a/2745086/2013738. We know `x + y` CAN overflow.
@@ -2125,7 +2140,7 @@ mod tests {
21252140 #[ test]
21262141 #[ should_panic]
21272142 fn decimal256_pow_overflow_panics ( ) {
2128- Decimal256 :: MAX . pow ( 2u32 ) ;
2143+ _ = Decimal256 :: MAX . pow ( 2u32 ) ;
21292144 }
21302145
21312146 #[ test]
0 commit comments