Эх сурвалжийг харах

Add Amount::convert_unit convenience method

David Caseria 3 сар өмнө
parent
commit
8d32af740e

+ 9 - 0
crates/cashu/src/amount.rs

@@ -172,6 +172,15 @@ impl Amount {
             acc.checked_add(x).ok_or(Error::AmountOverflow)
         })
     }
+
+    /// Convert unit
+    pub fn convert_unit(
+        &self,
+        current_unit: &CurrencyUnit,
+        target_unit: &CurrencyUnit,
+    ) -> Result<Amount, Error> {
+        to_unit(self.0, current_unit, target_unit)
+    }
 }
 
 impl Default for Amount {