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.
This commit is contained in:
Tobin C. Harding 2024-12-11 16:07:48 +11:00
parent 6ce5385914
commit 20a79da344
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 21 additions and 23 deletions

View File

@ -2,8 +2,7 @@
//! Implements `FeeRate` and assoctiated features. //! Implements `FeeRate` and assoctiated features.
use core::fmt; use core::{fmt, ops};
use core::ops::{Add, AddAssign, Div, Mul, Sub, SubAssign};
#[cfg(feature = "arbitrary")] #[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured}; use arbitrary::{Arbitrary, Unstructured};
@ -185,14 +184,14 @@ impl From<FeeRate> for u64 {
fn from(value: FeeRate) -> Self { value.to_sat_per_kwu() } fn from(value: FeeRate) -> Self { value.to_sat_per_kwu() }
} }
impl Add for FeeRate { impl ops::Add for FeeRate {
type Output = FeeRate; type Output = FeeRate;
fn add(self, rhs: FeeRate) -> Self::Output { FeeRate(self.0 + rhs.0) } fn add(self, rhs: FeeRate) -> Self::Output { FeeRate(self.0 + rhs.0) }
} }
crate::internal_macros::impl_add_for_references!(FeeRate); crate::internal_macros::impl_add_for_references!(FeeRate);
impl Sub for FeeRate { impl ops::Sub for FeeRate {
type Output = FeeRate; type Output = FeeRate;
fn sub(self, rhs: FeeRate) -> Self::Output { FeeRate(self.0 - rhs.0) } 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); crate::internal_macros::impl_sub_for_references!(FeeRate);
/// Computes the ceiling so that the fee computation is conservative. /// Computes the ceiling so that the fee computation is conservative.
impl Mul<FeeRate> for Weight { impl ops::Mul<FeeRate> for Weight {
type Output = Amount; type Output = Amount;
fn mul(self, rhs: FeeRate) -> Self::Output { fn mul(self, rhs: FeeRate) -> Self::Output {
@ -208,13 +207,13 @@ impl Mul<FeeRate> for Weight {
} }
} }
impl Mul<Weight> for FeeRate { impl ops::Mul<Weight> for FeeRate {
type Output = Amount; type Output = Amount;
fn mul(self, rhs: Weight) -> Self::Output { rhs * self } fn mul(self, rhs: Weight) -> Self::Output { rhs * self }
} }
impl Div<Weight> for Amount { impl ops::Div<Weight> for Amount {
type Output = FeeRate; type Output = FeeRate;
/// Truncating integer division. /// Truncating integer division.
@ -224,19 +223,19 @@ impl Div<Weight> for Amount {
fn div(self, rhs: Weight) -> Self::Output { FeeRate(self.to_sat() * 1000 / rhs.to_wu()) } 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 } 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 } 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 } 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 } fn sub_assign(&mut self, rhs: &FeeRate) { self.0 -= rhs.0 }
} }

View File

@ -2,8 +2,7 @@
//! Implements `Weight` and associated features. //! Implements `Weight` and associated features.
use core::fmt; use core::{fmt, ops};
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
#[cfg(feature = "arbitrary")] #[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured}; use arbitrary::{Arbitrary, Unstructured};
@ -167,55 +166,55 @@ impl From<Weight> for u64 {
fn from(value: Weight) -> Self { value.to_wu() } fn from(value: Weight) -> Self { value.to_wu() }
} }
impl Add for Weight { impl ops::Add for Weight {
type Output = Weight; type Output = Weight;
fn add(self, rhs: Weight) -> Self::Output { Weight(self.0 + rhs.0) } 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 } fn add_assign(&mut self, rhs: Self) { self.0 += rhs.0 }
} }
impl Sub for Weight { impl ops::Sub for Weight {
type Output = Weight; type Output = Weight;
fn sub(self, rhs: Weight) -> Self::Output { Weight(self.0 - rhs.0) } 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 } fn sub_assign(&mut self, rhs: Self) { self.0 -= rhs.0 }
} }
impl Mul<u64> for Weight { impl ops::Mul<u64> for Weight {
type Output = Weight; type Output = Weight;
fn mul(self, rhs: u64) -> Self::Output { Weight(self.0 * rhs) } fn mul(self, rhs: u64) -> Self::Output { Weight(self.0 * rhs) }
} }
impl Mul<Weight> for u64 { impl ops::Mul<Weight> for u64 {
type Output = Weight; type Output = Weight;
fn mul(self, rhs: Weight) -> Self::Output { Weight(self * rhs.0) } fn mul(self, rhs: Weight) -> Self::Output { Weight(self * rhs.0) }
} }
impl MulAssign<u64> for Weight { impl ops::MulAssign<u64> for Weight {
fn mul_assign(&mut self, rhs: u64) { self.0 *= rhs } fn mul_assign(&mut self, rhs: u64) { self.0 *= rhs }
} }
impl Div<u64> for Weight { impl ops::Div<u64> for Weight {
type Output = Weight; type Output = Weight;
fn div(self, rhs: u64) -> Self::Output { Weight(self.0 / rhs) } fn div(self, rhs: u64) -> Self::Output { Weight(self.0 / rhs) }
} }
impl Div<Weight> for Weight { impl ops::Div<Weight> for Weight {
type Output = u64; type Output = u64;
fn div(self, rhs: Weight) -> Self::Output { self.to_wu() / rhs.to_wu() } fn div(self, rhs: Weight) -> Self::Output { self.to_wu() / rhs.to_wu() }
} }
impl DivAssign<u64> for Weight { impl ops::DivAssign<u64> for Weight {
fn div_assign(&mut self, rhs: u64) { self.0 /= rhs } fn div_assign(&mut self, rhs: u64) { self.0 /= rhs }
} }