Skip to content

[Info] Cannot use U256::from(B256) due to ruint limitation #554

Closed as not planned
@greged93

Description

@greged93

Component

primitives

What version of Alloy are you on?

v0.6.4

Operating System

macOS (Apple Silicon)

Describe the bug

Despite the implementation of From<FixedBytes<N> for Uint<N*8>, it is currently not possible to run the below code:

use alloy_primitives::{FixedBytes, Uint};

fn main() {
    let fb = FixedBytes::<32>::new([1u8; 32]);
    let u = Uint::<256, 4>::from(fb);
    dbg!(u);
}

This is due to the line Uint::<256, 4>::from(fb), resolving the from to https://github.com/recmo/uint/blob/main/src/from.rs#L147, which requires the provided type to implement TryFrom and not From, causing the below error:

error[E0271]: type mismatch resolving `<Uint<256, 4> as TryFrom<FixedBytes<32>>>::Error == ToUintError<Uint<256, 4>>`
   --> src/main.rs:5:34
    |
5   |     let u = Uint::<256, 4>::from(fb);
    |             -------------------- ^^ expected `ToUintError<Uint<256, 4>>`, found `Infallible`
    |             |
    |             required by a bound introduced by this call
    |
    = note: expected enum `ToUintError<Uint<256, 4>>`
               found enum `Infallible`
    = note: required for `Uint<256, 4>` to implement `UintTryFrom<FixedBytes<32>>`
note: required by a bound in `ruint::from::<impl Uint<BITS, LIMBS>>::from`

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions