From 3317eb76d56fe4334f3847a6efe3aaebd29f1ba7 Mon Sep 17 00:00:00 2001
From: Frederik Gartenmeister <mustermeiszer@posteo.de>
Date: Sat, 24 Sep 2022 08:59:44 +0200
Subject: [PATCH] Const impls of base arithmetics for `Weights` with `u64`
 (#12322)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* 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>
---
 substrate/primitives/weights/src/weight_v2.rs | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/substrate/primitives/weights/src/weight_v2.rs b/substrate/primitives/weights/src/weight_v2.rs
index a4e4da4f8a7..af0f469ebaa 100644
--- a/substrate/primitives/weights/src/weight_v2.rs
+++ b/substrate/primitives/weights/src/weight_v2.rs
@@ -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 {
-- 
GitLab