substrate
substrate copied to clipboard
`Weight` function implementations unnecessarily verbose
Several of the Weight
implementations are (as the title states) unnecessarily verbose:
-
~~
checked_*
functions could be made much more succinct by using the?
operator~~ not possible, see https://github.com/rust-lang/rust/issues/74935 -
the
any_*
/all_*
functions all follow the same pattern:// all_* self.ref_time OP other.ref_time && self.proof_size OP other.proof_size // any_* self.ref_time OP other.ref_time || self.proof_size OP other.proof_size
which could very easily be implemented with a
macro_rules!
, and would reduce maintenance burden of any fields added in the future. -
~~the scalar arithmetic ops have their implementation duplicated, for example
mul
here:~~- ~~https://github.com/paritytech/substrate/blob/master/primitives/weights/src/weight_v2.rs#L274-L276~~
- ~~https://github.com/paritytech/substrate/blob/master/primitives/weights/src/weight_v2.rs#L365-L373~~
unfortunately not possible due to the current trait bounds on
<Weight as Mul<T>>::mul
~~Also, Weight
doesn't impl CheckedMul
, which I think it should.~~ not possible either
As always, happy to pick this up if it's accepted :slightly_smiling_face: