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`.
This commit is contained in:
Tobin C. Harding 2024-12-16 12:45:13 +11:00
parent 4d0f80f1fc
commit b895c9aad4
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 4 additions and 0 deletions

View File

@ -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.

View File

@ -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.