From 20a79da3443394f14b42abe5fe87b0e506e4ee97 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 Dec 2024 16:07:48 +1100 Subject: [PATCH] units: Use one level of path for ops traits Make all the `core::ops` impls in the `units` crate uniform by using a single level of path for the traits. --- units/src/fee_rate.rs | 21 ++++++++++----------- units/src/weight.rs | 23 +++++++++++------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/units/src/fee_rate.rs b/units/src/fee_rate.rs index eb3995ad4..1c2daad41 100644 --- a/units/src/fee_rate.rs +++ b/units/src/fee_rate.rs @@ -2,8 +2,7 @@ //! Implements `FeeRate` and assoctiated features. -use core::fmt; -use core::ops::{Add, AddAssign, Div, Mul, Sub, SubAssign}; +use core::{fmt, ops}; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; @@ -185,14 +184,14 @@ impl From for u64 { fn from(value: FeeRate) -> Self { value.to_sat_per_kwu() } } -impl Add for FeeRate { +impl ops::Add for FeeRate { type Output = FeeRate; fn add(self, rhs: FeeRate) -> Self::Output { FeeRate(self.0 + rhs.0) } } crate::internal_macros::impl_add_for_references!(FeeRate); -impl Sub for FeeRate { +impl ops::Sub for FeeRate { type Output = FeeRate; fn sub(self, rhs: FeeRate) -> Self::Output { FeeRate(self.0 - rhs.0) } @@ -200,7 +199,7 @@ impl Sub for FeeRate { crate::internal_macros::impl_sub_for_references!(FeeRate); /// Computes the ceiling so that the fee computation is conservative. -impl Mul for Weight { +impl ops::Mul for Weight { type Output = Amount; fn mul(self, rhs: FeeRate) -> Self::Output { @@ -208,13 +207,13 @@ impl Mul for Weight { } } -impl Mul for FeeRate { +impl ops::Mul for FeeRate { type Output = Amount; fn mul(self, rhs: Weight) -> Self::Output { rhs * self } } -impl Div for Amount { +impl ops::Div for Amount { type Output = FeeRate; /// Truncating integer division. @@ -224,19 +223,19 @@ impl Div for Amount { fn div(self, rhs: Weight) -> Self::Output { FeeRate(self.to_sat() * 1000 / rhs.to_wu()) } } -impl AddAssign for FeeRate { +impl ops::AddAssign for FeeRate { fn add_assign(&mut self, rhs: Self) { self.0 += rhs.0 } } -impl AddAssign<&FeeRate> for FeeRate { +impl ops::AddAssign<&FeeRate> for FeeRate { fn add_assign(&mut self, rhs: &FeeRate) { self.0 += rhs.0 } } -impl SubAssign for FeeRate { +impl ops::SubAssign for FeeRate { fn sub_assign(&mut self, rhs: Self) { self.0 -= rhs.0 } } -impl SubAssign<&FeeRate> for FeeRate { +impl ops::SubAssign<&FeeRate> for FeeRate { fn sub_assign(&mut self, rhs: &FeeRate) { self.0 -= rhs.0 } } diff --git a/units/src/weight.rs b/units/src/weight.rs index a8b1e94cb..717b3813b 100644 --- a/units/src/weight.rs +++ b/units/src/weight.rs @@ -2,8 +2,7 @@ //! Implements `Weight` and associated features. -use core::fmt; -use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; +use core::{fmt, ops}; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; @@ -167,55 +166,55 @@ impl From for u64 { fn from(value: Weight) -> Self { value.to_wu() } } -impl Add for Weight { +impl ops::Add for Weight { type Output = Weight; fn add(self, rhs: Weight) -> Self::Output { Weight(self.0 + rhs.0) } } -impl AddAssign for Weight { +impl ops::AddAssign for Weight { fn add_assign(&mut self, rhs: Self) { self.0 += rhs.0 } } -impl Sub for Weight { +impl ops::Sub for Weight { type Output = Weight; fn sub(self, rhs: Weight) -> Self::Output { Weight(self.0 - rhs.0) } } -impl SubAssign for Weight { +impl ops::SubAssign for Weight { fn sub_assign(&mut self, rhs: Self) { self.0 -= rhs.0 } } -impl Mul for Weight { +impl ops::Mul for Weight { type Output = Weight; fn mul(self, rhs: u64) -> Self::Output { Weight(self.0 * rhs) } } -impl Mul for u64 { +impl ops::Mul for u64 { type Output = Weight; fn mul(self, rhs: Weight) -> Self::Output { Weight(self * rhs.0) } } -impl MulAssign for Weight { +impl ops::MulAssign for Weight { fn mul_assign(&mut self, rhs: u64) { self.0 *= rhs } } -impl Div for Weight { +impl ops::Div for Weight { type Output = Weight; fn div(self, rhs: u64) -> Self::Output { Weight(self.0 / rhs) } } -impl Div for Weight { +impl ops::Div for Weight { type Output = u64; fn div(self, rhs: Weight) -> Self::Output { self.to_wu() / rhs.to_wu() } } -impl DivAssign for Weight { +impl ops::DivAssign for Weight { fn div_assign(&mut self, rhs: u64) { self.0 /= rhs } }