substrate
substrate copied to clipboard
Const impls of base arithmetics for `Weights` with `u64`
Not sure, if this is essentially needed, but with respect to consts, which will be one of the common usages of Weights as runtime parameters, I am not a fan of saturating operations and the checked versions are currently not really usable as unwrap() is not available for consts.
The additional methods allow for usage of weights as const SOME_WEIGHT: Weight = OTHER_WEIGHT.div(2)
E.g.
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2does not work, which is fine.const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.checked_div(2).unwrap()does not work, which is not so fine, as we don't want anOption<Weight>const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_add(u64::MAX)does work, but assumingWEIGHT_PER_SECONDis bigger thanu64::MAXa compilation error would be prefered .