From b895c9aad4e56ff7cf5420f71ae501f942a81326 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 16 Dec 2024 12:45:13 +1100 Subject: [PATCH] units: Deprecate unchecked ops These functions do not add value because one can just call `to_sat` and `from_sat` if doing ops in a tight loop. Note we need to remove these deprecated functions before we release `units v1.0`. --- units/src/amount/signed.rs | 2 ++ units/src/amount/unsigned.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/units/src/amount/signed.rs b/units/src/amount/signed.rs index 0ce121425..efe160e71 100644 --- a/units/src/amount/signed.rs +++ b/units/src/amount/signed.rs @@ -318,6 +318,7 @@ impl SignedAmount { /// /// On overflow, panics in debug mode, wraps in release mode. #[must_use] + #[deprecated(since = "TBD", note = "consider converting to u64 using `to_sat`")] pub fn unchecked_add(self, rhs: SignedAmount) -> SignedAmount { Self(self.0 + rhs.0) } /// Unchecked subtraction. @@ -328,6 +329,7 @@ impl SignedAmount { /// /// On overflow, panics in debug mode, wraps in release mode. #[must_use] + #[deprecated(since = "TBD", note = "consider converting to u64 using `to_sat`")] pub fn unchecked_sub(self, rhs: SignedAmount) -> SignedAmount { Self(self.0 - rhs.0) } /// Subtraction that doesn't allow negative [`SignedAmount`]s. diff --git a/units/src/amount/unsigned.rs b/units/src/amount/unsigned.rs index 8fa95eece..cb39301cb 100644 --- a/units/src/amount/unsigned.rs +++ b/units/src/amount/unsigned.rs @@ -394,6 +394,7 @@ impl Amount { /// /// On overflow, panics in debug mode, wraps in release mode. #[must_use] + #[deprecated(since = "TBD", note = "consider converting to u64 using `to_sat`")] pub fn unchecked_add(self, rhs: Amount) -> Amount { Self(self.0 + rhs.0) } /// Unchecked subtraction. @@ -404,6 +405,7 @@ impl Amount { /// /// On overflow, panics in debug mode, wraps in release mode. #[must_use] + #[deprecated(since = "TBD", note = "consider converting to u64 using `to_sat`")] pub fn unchecked_sub(self, rhs: Amount) -> Amount { Self(self.0 - rhs.0) } /// Converts to a signed amount.