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

docs.rs homepage examples use rand_core crate option, but do not mention its existence #633

Closed
samuela opened this issue Feb 23, 2024 · 2 comments · Fixed by #641
Closed

Comments

@samuela
Copy link

samuela commented Feb 23, 2024

I'm attempting to follow the documentation and have the following file:

use ed25519_dalek::SigningKey;
use rand::rngs::OsRng;

fn main() {
  let mut csprng = OsRng;
  let signing_key: SigningKey = SigningKey::generate(&mut csprng);
}

which I'm attempting to build against ed25519_dalek 2.1.1 and rand 0.8.5 but I'm getting the following error:

error[E0599]: no function or associated item named `generate` found for struct `SigningKey` in the current scope
 --> src/bin/foo.rs:6:45
  |
6 |   let signing_key: SigningKey = SigningKey::generate(&mut csprng);
  |                                             ^^^^^^^^ function or associated item not found in `SigningKey`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `cherami` (bin "foo") due to previous error
@tarcieri
Copy link
Contributor

I agree that example is deficient and doesn't fully explain everything you need to do for the generate method to be available.

For more information, see the documentation here, note "available on crate feature rand_core only":

https://docs.rs/ed25519-dalek/latest/ed25519_dalek/struct.SigningKey.html#method.generate

Screenshot 2024-02-22 at 6 34 39 PM

Solution: you need to enable the rand_core crate feature in Cargo.toml:

[dependencies]
ed25519-dalek = { version = "2", features = ["rand_core"] }

@samuela
Copy link
Author

samuela commented Feb 23, 2024

Thanks @tarcieri ! That indeed solves the compilation error. I was not aware of the rand_core option after reading https://docs.rs/ed25519-dalek/latest/ed25519_dalek/.

I will update the issue title to reflect a docs issue, instead of a compilation one.

@samuela samuela changed the title "error[E0599]: no function or associated item named generate found for struct SigningKey in the current scope" docs.rs homepage examples use rand_core crate option, but do not mention its existence Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants