From 4787aa1f896df4857d8cf4051ce96c2b531f35ad Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Mon, 3 Mar 2025 17:36:26 +0000 Subject: [PATCH] Implement Rem for Weight `Weight` implements `Div` but not `Rem` Add `Rem` impl for `Weight` --- units/src/weight.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/units/src/weight.rs b/units/src/weight.rs index 720dfd385..533158e0a 100644 --- a/units/src/weight.rs +++ b/units/src/weight.rs @@ -198,6 +198,16 @@ crate::internal_macros::impl_op_for_references! { fn div(self, rhs: Weight) -> Self::Output { self.to_wu() / rhs.to_wu() } } + impl ops::Rem for Weight { + type Output = Weight; + + fn rem(self, rhs: u64) -> Self::Output { Weight(self.0 % rhs) } + } + impl ops::Rem for Weight { + type Output = u64; + + fn rem(self, rhs: Weight) -> Self::Output { self.0 % rhs.0 } + } } crate::internal_macros::impl_add_assign!(Weight); crate::internal_macros::impl_sub_assign!(Weight); @@ -210,6 +220,10 @@ impl ops::DivAssign for Weight { fn div_assign(&mut self, rhs: u64) { self.0 /= rhs } } +impl ops::RemAssign for Weight { + fn rem_assign(&mut self, rhs: u64) { self.0 %= rhs } +} + impl core::iter::Sum for Weight { fn sum(iter: I) -> Self where