Reputation: 1298
I've been trying to implement the example given in the following doc: https://docs.rs/ed25519-dalek/1.0.1/ed25519_dalek/
My code is simply:
extern crate rand;
extern crate ed25519_dalek;
use rand::rngs::OsRng;
use ed25519_dalek::Keypair;
fn main() {
let mut csprng = OsRng{};
let keypair: Keypair = Keypair::generate(&mut csprng);
}
But when I try to run I get an error saying that the CryptoRng
trait is not implemented in OsRng
11 | let keypair: Keypair = Keypair::generate(&mut csprng);
| ^^^^^^^^^^^ the trait `rand_core::CryptoRng` is not implemented for `OsRng`
However, CryptoRng
is simply a marker trait, and I saw that it indeed has an empty impl for OsRng
...
So what could be the issue here?
Upvotes: 9
Views: 3533
Reputation: 35512
Usually when you get these confusing messages saying "trait bound not met" when it's clearly met, or "wrong type" when it's clearly the right type, you should always check package versions. As of right now (ed25519-dalek v1.0.1), it depends on rand 0.7.0 (you can also find this on crates.io). You're using a newer version of rand, with a "newer" version of the trait, and it's looking for the 0.7.0 trait while you supply the 0.8.0 trait.
The solution? Either downgrade rand to 0.7.0 or use dependency renaming to have 2 versions of rand, and use the old version for ec25519-dalek.
Upvotes: 17