Const impls of base arithmetics for Weights with u64 (#12322)

* Const impls

* Adding explainatory comments

* Update primitives/weights/src/weight_v2.rs

Doc comment suggestions

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update primitives/weights/src/weight_v2.rs

Doc comment suggestions

Co-authored-by: Bastian Köcher <git@kchr.de>

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Frederik Gartenmeister
2022-09-24 08:59:44 +02:00
committed by GitHub
parent bf97f2a702
commit 3317eb76d5
@@ -160,6 +160,34 @@ impl Weight {
Self { ref_time: 0 }
}
/// Constant version of Add with u64.
///
/// Is only overflow safe when evaluated at compile-time.
pub const fn add(self, scalar: u64) -> Self {
Self { ref_time: self.ref_time + scalar }
}
/// Constant version of Sub with u64.
///
/// Is only overflow safe when evaluated at compile-time.
pub const fn sub(self, scalar: u64) -> Self {
Self { ref_time: self.ref_time - scalar }
}
/// Constant version of Div with u64.
///
/// Is only overflow safe when evaluated at compile-time.
pub const fn div(self, scalar: u64) -> Self {
Self { ref_time: self.ref_time / scalar }
}
/// Constant version of Mul with u64.
///
/// Is only overflow safe when evaluated at compile-time.
pub const fn mul(self, scalar: u64) -> Self {
Self { ref_time: self.ref_time * scalar }
}
/// Returns true if any of `self`'s constituent weights is strictly greater than that of the
/// `other`'s, otherwise returns false.
pub const fn any_gt(self, other: Self) -> bool {