How to convert Weight to u64 and the other way around
You cannot convert Weigth
to a single u64
, since it is (currently) two dimensional. You can split and construct it from its components like this:
let weight = Weight::from_parts(10, 20);
let ref_time = weight.ref_time();
let proof_size = weight.proof_size();
let weight = Weight::from_parts(ref_time, proof_size);
But what if I wanted to multiply it with a fraction(e.g. Perbill)?
Well... just do it?
#[test]
fn per_thing_mul_works() {
let weight = Weight::from_parts(80, 60);
let half = sp_arithmetic::Perbill::from_percent(50);
assert_eq!(weight * half, Weight::from_parts(40, 30));
assert_eq!(half * weight, Weight::from_parts(40, 30));
}