From 0a16382fa349e17e07576f7d056025fd09a332bd Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 23 Dec 2024 14:40:56 +1100 Subject: [PATCH 1/2] Rename rhs to weight In ops functions we typically use `rhs` but for the more unconventional `checked_*_by_*` functions lets use a more descriptive parameter name. This is an internal change but the api files are updated because the paramater names appear in the api text files. --- units/src/amount/unsigned.rs | 8 ++++---- units/src/fee_rate.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/units/src/amount/unsigned.rs b/units/src/amount/unsigned.rs index 49edb71be..e7b214189 100644 --- a/units/src/amount/unsigned.rs +++ b/units/src/amount/unsigned.rs @@ -369,8 +369,8 @@ impl Amount { /// ``` #[cfg(feature = "alloc")] #[must_use] - pub const fn checked_div_by_weight_ceil(self, rhs: Weight) -> Option { - let wu = rhs.to_wu(); + pub const fn checked_div_by_weight_ceil(self, weight: Weight) -> Option { + let wu = weight.to_wu(); // No `?` operator in const context. if let Some(sats) = self.0.checked_mul(1_000) { if let Some(wu_minus_one) = wu.checked_sub(1) { @@ -392,10 +392,10 @@ impl Amount { /// Returns [`None`] if overflow occurred. #[cfg(feature = "alloc")] #[must_use] - pub const fn checked_div_by_weight_floor(self, rhs: Weight) -> Option { + pub const fn checked_div_by_weight_floor(self, weight: Weight) -> Option { // No `?` operator in const context. match self.0.checked_mul(1_000) { - Some(res) => match res.checked_div(rhs.to_wu()) { + Some(res) => match res.checked_div(weight.to_wu()) { Some(fee_rate) => Some(FeeRate::from_sat_per_kwu(fee_rate)), None => None, }, diff --git a/units/src/fee_rate.rs b/units/src/fee_rate.rs index 3429aa44a..8c9b79d3d 100644 --- a/units/src/fee_rate.rs +++ b/units/src/fee_rate.rs @@ -108,9 +108,9 @@ impl FeeRate { /// /// [`None`] is returned if an overflow occurred. #[must_use] - pub const fn checked_mul_by_weight(self, rhs: Weight) -> Option { + pub const fn checked_mul_by_weight(self, weight: Weight) -> Option { // No `?` operator in const context. - match self.0.checked_mul(rhs.to_wu()) { + match self.0.checked_mul(weight.to_wu()) { Some(mul_res) => match mul_res.checked_add(999) { Some(add_res) => Some(Amount::from_sat(add_res / 1000)), None => None, From 29811ba82cc598d08dc877825ecf8890c48d23b7 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 23 Dec 2024 15:49:33 +1100 Subject: [PATCH 2/2] api: Run just check-api Note that the changes here are not actually API breaking changes, they are only changes to the parameter name. --- api/units/all-features.txt | 6 +++--- api/units/alloc-only.txt | 6 +++--- api/units/no-features.txt | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/units/all-features.txt b/api/units/all-features.txt index 23ad868e2..b6fe439c6 100644 --- a/api/units/all-features.txt +++ b/api/units/all-features.txt @@ -713,8 +713,8 @@ pub const bitcoin_units::weight::Weight::WITNESS_SCALE_FACTOR: u64 pub const bitcoin_units::weight::Weight::ZERO: bitcoin_units::weight::Weight pub const fn bitcoin_units::Amount::checked_add(self, rhs: bitcoin_units::Amount) -> core::option::Option pub const fn bitcoin_units::Amount::checked_div(self, rhs: u64) -> core::option::Option -pub const fn bitcoin_units::Amount::checked_div_by_weight_ceil(self, rhs: bitcoin_units::weight::Weight) -> core::option::Option -pub const fn bitcoin_units::Amount::checked_div_by_weight_floor(self, rhs: bitcoin_units::weight::Weight) -> core::option::Option +pub const fn bitcoin_units::Amount::checked_div_by_weight_ceil(self, weight: bitcoin_units::weight::Weight) -> core::option::Option +pub const fn bitcoin_units::Amount::checked_div_by_weight_floor(self, weight: bitcoin_units::weight::Weight) -> core::option::Option pub const fn bitcoin_units::Amount::checked_mul(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::Amount::checked_rem(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::Amount::checked_sub(self, rhs: bitcoin_units::Amount) -> core::option::Option @@ -737,7 +737,7 @@ pub const fn bitcoin_units::block::BlockInterval::to_u32(self) -> u32 pub const fn bitcoin_units::fee_rate::FeeRate::checked_add(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::checked_div(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::checked_mul(self, rhs: u64) -> core::option::Option -pub const fn bitcoin_units::fee_rate::FeeRate::checked_mul_by_weight(self, rhs: bitcoin_units::weight::Weight) -> core::option::Option +pub const fn bitcoin_units::fee_rate::FeeRate::checked_mul_by_weight(self, weight: bitcoin_units::weight::Weight) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::checked_sub(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::from_sat_per_kvb(sat_kvb: u64) -> Self pub const fn bitcoin_units::fee_rate::FeeRate::from_sat_per_kwu(sat_kwu: u64) -> Self diff --git a/api/units/alloc-only.txt b/api/units/alloc-only.txt index ae1768dec..365d8d466 100644 --- a/api/units/alloc-only.txt +++ b/api/units/alloc-only.txt @@ -664,8 +664,8 @@ pub const bitcoin_units::weight::Weight::WITNESS_SCALE_FACTOR: u64 pub const bitcoin_units::weight::Weight::ZERO: bitcoin_units::weight::Weight pub const fn bitcoin_units::Amount::checked_add(self, rhs: bitcoin_units::Amount) -> core::option::Option pub const fn bitcoin_units::Amount::checked_div(self, rhs: u64) -> core::option::Option -pub const fn bitcoin_units::Amount::checked_div_by_weight_ceil(self, rhs: bitcoin_units::weight::Weight) -> core::option::Option -pub const fn bitcoin_units::Amount::checked_div_by_weight_floor(self, rhs: bitcoin_units::weight::Weight) -> core::option::Option +pub const fn bitcoin_units::Amount::checked_div_by_weight_ceil(self, weight: bitcoin_units::weight::Weight) -> core::option::Option +pub const fn bitcoin_units::Amount::checked_div_by_weight_floor(self, weight: bitcoin_units::weight::Weight) -> core::option::Option pub const fn bitcoin_units::Amount::checked_mul(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::Amount::checked_rem(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::Amount::checked_sub(self, rhs: bitcoin_units::Amount) -> core::option::Option @@ -688,7 +688,7 @@ pub const fn bitcoin_units::block::BlockInterval::to_u32(self) -> u32 pub const fn bitcoin_units::fee_rate::FeeRate::checked_add(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::checked_div(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::checked_mul(self, rhs: u64) -> core::option::Option -pub const fn bitcoin_units::fee_rate::FeeRate::checked_mul_by_weight(self, rhs: bitcoin_units::weight::Weight) -> core::option::Option +pub const fn bitcoin_units::fee_rate::FeeRate::checked_mul_by_weight(self, weight: bitcoin_units::weight::Weight) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::checked_sub(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::from_sat_per_kvb(sat_kvb: u64) -> Self pub const fn bitcoin_units::fee_rate::FeeRate::from_sat_per_kwu(sat_kwu: u64) -> Self diff --git a/api/units/no-features.txt b/api/units/no-features.txt index 197e438eb..fa7f4538d 100644 --- a/api/units/no-features.txt +++ b/api/units/no-features.txt @@ -670,7 +670,7 @@ pub const fn bitcoin_units::block::BlockInterval::to_u32(self) -> u32 pub const fn bitcoin_units::fee_rate::FeeRate::checked_add(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::checked_div(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::checked_mul(self, rhs: u64) -> core::option::Option -pub const fn bitcoin_units::fee_rate::FeeRate::checked_mul_by_weight(self, rhs: bitcoin_units::weight::Weight) -> core::option::Option +pub const fn bitcoin_units::fee_rate::FeeRate::checked_mul_by_weight(self, weight: bitcoin_units::weight::Weight) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::checked_sub(self, rhs: u64) -> core::option::Option pub const fn bitcoin_units::fee_rate::FeeRate::from_sat_per_kvb(sat_kvb: u64) -> Self pub const fn bitcoin_units::fee_rate::FeeRate::from_sat_per_kwu(sat_kwu: u64) -> Self