From 3196c271acefe2b68783c8bc128c75942c978ba2 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 3 Jul 2024 07:38:58 +0200 Subject: [PATCH] Deprecate `Amount::fmt_value_in` `fmt_value_in` was added when `display_in` wasn't available. However common usage patterns seem to favor `display_in`. It can be used within format strings and supports formatting options. Removing it will simplify the codebase, so this deprecates it. --- units/src/amount.rs | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/units/src/amount.rs b/units/src/amount.rs index cc5431ec6..c8513ece5 100644 --- a/units/src/amount.rs +++ b/units/src/amount.rs @@ -8,8 +8,6 @@ #[cfg(feature = "alloc")] use alloc::string::{String, ToString}; use core::cmp::Ordering; -#[cfg(feature = "alloc")] -use core::fmt::Write as _; use core::str::FromStr; use core::{default, fmt, ops}; @@ -986,6 +984,7 @@ impl Amount { /// /// Does not include the denomination. #[rustfmt::skip] + #[deprecated(since = "TBD", note = "Use `display_in()` instead")] pub fn fmt_value_in(self, f: &mut dyn fmt::Write, denom: Denomination) -> fmt::Result { fmt_satoshi_in(self.to_sat(), false, f, denom, false, FormatOptions::default()) } @@ -995,19 +994,14 @@ impl Amount { /// Does not include the denomination. #[cfg(feature = "alloc")] pub fn to_string_in(self, denom: Denomination) -> String { - let mut buf = String::new(); - self.fmt_value_in(&mut buf, denom).unwrap(); - buf + self.display_in(denom).to_string() } /// Get a formatted string of this [Amount] in the given denomination, /// suffixed with the abbreviation for the denomination. #[cfg(feature = "alloc")] pub fn to_string_with_denomination(self, denom: Denomination) -> String { - let mut buf = String::new(); - self.fmt_value_in(&mut buf, denom).unwrap(); - write!(buf, " {}", denom).unwrap(); - buf + self.display_in(denom).show_denomination().to_string() } // Some arithmetic that doesn't fit in `core::ops` traits. @@ -1348,6 +1342,7 @@ impl SignedAmount { /// /// Does not include the denomination. #[rustfmt::skip] + #[deprecated(since = "TBD", note = "Use `display_in()` instead")] pub fn fmt_value_in(self, f: &mut dyn fmt::Write, denom: Denomination) -> fmt::Result { fmt_satoshi_in(self.unsigned_abs().to_sat(), self.is_negative(), f, denom, false, FormatOptions::default()) } @@ -1357,19 +1352,14 @@ impl SignedAmount { /// Does not include the denomination. #[cfg(feature = "alloc")] pub fn to_string_in(self, denom: Denomination) -> String { - let mut buf = String::new(); - self.fmt_value_in(&mut buf, denom).unwrap(); - buf + self.display_in(denom).to_string() } /// Get a formatted string of this [SignedAmount] in the given denomination, /// suffixed with the abbreviation for the denomination. #[cfg(feature = "alloc")] pub fn to_string_with_denomination(self, denom: Denomination) -> String { - let mut buf = String::new(); - self.fmt_value_in(&mut buf, denom).unwrap(); - write!(buf, " {}", denom).unwrap(); - buf + self.display_in(denom).show_denomination().to_string() } // Some arithmetic that doesn't fit in `core::ops` traits.