Merge rust-bitcoin/rust-bitcoin#3032: Move impl above tests
301fe9fad9
Move impl above tests (yancy) Pull request description: It's common in other modules for the tests to be at the end of the file. Moving the tests to the bottom helps the code base uniformity. Pulled from stale PR 2215 ACKs for top commit: shinghim: ACK301fe9fad9
tcharding: ACK301fe9fad9
Kixunil: ACK301fe9fad9
Tree-SHA512: c749c4c2c5fba2c8a57fe034d4ef5d34ff26baddb1b2148b9778dc554c955ad31c7bc83b89a3647228bf5f175adddb03105a1e494b28f5a7955369abaa11cfd1
This commit is contained in:
commit
36d5c471cf
|
@ -135,6 +135,82 @@ impl fmt::Display for Weight {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Weight> for u64 {
|
||||
fn from(value: Weight) -> Self { value.to_wu() }
|
||||
}
|
||||
|
||||
impl Add for Weight {
|
||||
type Output = Weight;
|
||||
|
||||
fn add(self, rhs: Weight) -> Self::Output { Weight(self.0 + rhs.0) }
|
||||
}
|
||||
|
||||
impl AddAssign for Weight {
|
||||
fn add_assign(&mut self, rhs: Self) { self.0 += rhs.0 }
|
||||
}
|
||||
|
||||
impl Sub for Weight {
|
||||
type Output = Weight;
|
||||
|
||||
fn sub(self, rhs: Weight) -> Self::Output { Weight(self.0 - rhs.0) }
|
||||
}
|
||||
|
||||
impl SubAssign for Weight {
|
||||
fn sub_assign(&mut self, rhs: Self) { self.0 -= rhs.0 }
|
||||
}
|
||||
|
||||
impl Mul<u64> for Weight {
|
||||
type Output = Weight;
|
||||
|
||||
fn mul(self, rhs: u64) -> Self::Output { Weight(self.0 * rhs) }
|
||||
}
|
||||
|
||||
impl Mul<Weight> for u64 {
|
||||
type Output = Weight;
|
||||
|
||||
fn mul(self, rhs: Weight) -> Self::Output { Weight(self * rhs.0) }
|
||||
}
|
||||
|
||||
impl MulAssign<u64> for Weight {
|
||||
fn mul_assign(&mut self, rhs: u64) { self.0 *= rhs }
|
||||
}
|
||||
|
||||
impl Div<u64> for Weight {
|
||||
type Output = Weight;
|
||||
|
||||
fn div(self, rhs: u64) -> Self::Output { Weight(self.0 / rhs) }
|
||||
}
|
||||
|
||||
impl Div<Weight> for Weight {
|
||||
type Output = u64;
|
||||
|
||||
fn div(self, rhs: Weight) -> Self::Output { self.to_wu() / rhs.to_wu() }
|
||||
}
|
||||
|
||||
impl DivAssign<u64> for Weight {
|
||||
fn div_assign(&mut self, rhs: u64) { self.0 /= rhs }
|
||||
}
|
||||
|
||||
impl core::iter::Sum for Weight {
|
||||
fn sum<I>(iter: I) -> Self
|
||||
where
|
||||
I: Iterator<Item = Self>,
|
||||
{
|
||||
Weight(iter.map(Weight::to_wu).sum())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> core::iter::Sum<&'a Weight> for Weight {
|
||||
fn sum<I>(iter: I) -> Self
|
||||
where
|
||||
I: Iterator<Item = &'a Weight>,
|
||||
{
|
||||
iter.cloned().sum()
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_parse_str_from_int_infallible!(Weight, u64, from_wu);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -246,79 +322,3 @@ mod tests {
|
|||
assert_eq!(None, result);
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Weight> for u64 {
|
||||
fn from(value: Weight) -> Self { value.to_wu() }
|
||||
}
|
||||
|
||||
impl Add for Weight {
|
||||
type Output = Weight;
|
||||
|
||||
fn add(self, rhs: Weight) -> Self::Output { Weight(self.0 + rhs.0) }
|
||||
}
|
||||
|
||||
impl AddAssign for Weight {
|
||||
fn add_assign(&mut self, rhs: Self) { self.0 += rhs.0 }
|
||||
}
|
||||
|
||||
impl Sub for Weight {
|
||||
type Output = Weight;
|
||||
|
||||
fn sub(self, rhs: Weight) -> Self::Output { Weight(self.0 - rhs.0) }
|
||||
}
|
||||
|
||||
impl SubAssign for Weight {
|
||||
fn sub_assign(&mut self, rhs: Self) { self.0 -= rhs.0 }
|
||||
}
|
||||
|
||||
impl Mul<u64> for Weight {
|
||||
type Output = Weight;
|
||||
|
||||
fn mul(self, rhs: u64) -> Self::Output { Weight(self.0 * rhs) }
|
||||
}
|
||||
|
||||
impl Mul<Weight> for u64 {
|
||||
type Output = Weight;
|
||||
|
||||
fn mul(self, rhs: Weight) -> Self::Output { Weight(self * rhs.0) }
|
||||
}
|
||||
|
||||
impl MulAssign<u64> for Weight {
|
||||
fn mul_assign(&mut self, rhs: u64) { self.0 *= rhs }
|
||||
}
|
||||
|
||||
impl Div<u64> for Weight {
|
||||
type Output = Weight;
|
||||
|
||||
fn div(self, rhs: u64) -> Self::Output { Weight(self.0 / rhs) }
|
||||
}
|
||||
|
||||
impl Div<Weight> for Weight {
|
||||
type Output = u64;
|
||||
|
||||
fn div(self, rhs: Weight) -> Self::Output { self.to_wu() / rhs.to_wu() }
|
||||
}
|
||||
|
||||
impl DivAssign<u64> for Weight {
|
||||
fn div_assign(&mut self, rhs: u64) { self.0 /= rhs }
|
||||
}
|
||||
|
||||
impl core::iter::Sum for Weight {
|
||||
fn sum<I>(iter: I) -> Self
|
||||
where
|
||||
I: Iterator<Item = Self>,
|
||||
{
|
||||
Weight(iter.map(Weight::to_wu).sum())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> core::iter::Sum<&'a Weight> for Weight {
|
||||
fn sum<I>(iter: I) -> Self
|
||||
where
|
||||
I: Iterator<Item = &'a Weight>,
|
||||
{
|
||||
iter.cloned().sum()
|
||||
}
|
||||
}
|
||||
|
||||
crate::impl_parse_str_from_int_infallible!(Weight, u64, from_wu);
|
||||
|
|
Loading…
Reference in New Issue