-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Weight
function implementations unnecessarily verbose
#13265
Comments
I'm not convinced by this, because this isn't changing that often.
Fine point, the trait could call the const method.
Also okay. |
For the first point, I was thinking that it would be nice to define those through a sort of "pseudo-function-composition", and cut down on the boilerplate a bit (the maintenance cost was just a nice bonus), like this: https://gist.github.com/benluelo/07d58471716ef211cd359b915bea4021. Some unfortunate issues:
Also, for |
About the syntax: We actually want less syntax magic and more data driven so that downstream tooling can easier parse it: paritytech/polkadot-sdk#382 |
Several of the
Weight
implementations are (as the title states) unnecessarily verbose:not possible, see Tracking Issue for the use ofchecked_*
functions could be made much more succinct by using the?
operator?
in constants rust-lang/rust#74935the
any_*
/all_*
functions all follow the same pattern: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 examplemul
here:https://github.com/paritytech/substrate/blob/master/primitives/weights/src/weight_v2.rs#L274-L276https://github.com/paritytech/substrate/blob/master/primitives/weights/src/weight_v2.rs#L365-L373unfortunately not possible due to the current trait bounds on
<Weight as Mul<T>>::mul
Also,not possible eitherWeight
doesn't implCheckedMul
, which I think it should.As always, happy to pick this up if it's accepted 🙂
The text was updated successfully, but these errors were encountered: