Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] enabling rand feature for re-exported ruint crate #381

Closed
cool-mestorf opened this issue Oct 24, 2023 · 0 comments · Fixed by #385
Closed

[Feature] enabling rand feature for re-exported ruint crate #381

cool-mestorf opened this issue Oct 24, 2023 · 0 comments · Fixed by #385
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@cool-mestorf
Copy link
Contributor

Component

primitives

Describe the feature you would like

using alloy-primitives with rand feature enabled does not enable re-exported ruint::Uint type's rand related trait implementation.

# Cargo.toml
[dependencies]
alloy-primitives = {version="0.4.2", features=["rand"]}
rand = "0.8.5"
// main.rs
use alloy_primitives::U256;
use rand::{thread_rng, Rng};

fn main() {
    let mut rng = thread_rng();
    let u: U256 = rng.gen();
    println!("{}", u);
}
error[E0277]: the trait bound `Standard: Distribution<Uint<256, 4>>` is not satisfied
  --> src/main.rs:6:23
   |
6  |     let u: U256 = rng.gen();
   |                       ^^^ the trait `Distribution<Uint<256, 4>>` is not implemented for `Standard`
   |

I expect a single line fix can solve this issue:

diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml
index 4309bc6..86ea6a7 100644
--- a/crates/primitives/Cargo.toml
+++ b/crates/primitives/Cargo.toml
@@ -66,7 +66,7 @@ std = [
 tiny-keccak = []
 native-keccak = []
 getrandom = ["dep:getrandom"]
-rand = ["dep:rand", "getrandom"]
+rand = ["dep:rand", "getrandom", "ruint/rand"]
 rlp = ["dep:alloy-rlp", "ruint/alloy-rlp"]
 serde = ["dep:serde", "bytes/serde", "hex/serde", "ruint/serde"]
 arbitrary = [

Additional context

No response

@cool-mestorf cool-mestorf added the enhancement New feature or request label Oct 24, 2023
@DaniPopes DaniPopes added the good first issue Good for newcomers label Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants