Forráskód Böngészése

Add Amount::convert_unit convenience method

David Caseria 3 hónapja
szülő
commit
8d32af740e
1 módosított fájl, 9 hozzáadás és 0 törlés
  1. 9 0
      crates/cashu/src/amount.rs

+ 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 {