parity-common icon indicating copy to clipboard operation
parity-common copied to clipboard

U types do not convert to each other

Open rakanalh opened this issue 3 years ago • 2 comments

Hello,

Is there a reason why U* types do not implement From/Into from each other? At least to be able to cast upwards.

Example,

impl From<U64> for U128 {
    fn from(num: U64) -> Self {
        num.low_u64().into() // U128 implements From<u64>
    }
}

impl From<U64> for U256 {
    fn from(num: U64) -> Self {
        num.low_u64().into() // U256 implements From<u64>
    }
}

rakanalh avatar Jul 13 '21 18:07 rakanalh

they do in primitive-types https://github.com/paritytech/parity-common/blob/2d571df7fee92b85b47b49cf14aa3a7641f2f3b9/primitive-types/src/lib.rs#L146-L252

anything missing?

ordian avatar Jul 13 '21 19:07 ordian

U64 is kind of legacy, see https://github.com/paritytech/parity-common/pull/473 but we can probably add conversions from it in ethereum-types

ordian avatar Jul 13 '21 19:07 ordian