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

Code in digest README is not valid #1072

Closed
jwodder opened this issue Aug 6, 2022 · 1 comment · Fixed by #1109
Closed

Code in digest README is not valid #1072

jwodder opened this issue Aug 6, 2022 · 1 comment · Fixed by #1109

Comments

@jwodder
Copy link

jwodder commented Aug 6, 2022

The README for the digest crate currently contains the following example:

use blake2::{Blake2b, Digest};

let mut hasher = Blake2b::new();
let data = b"Hello world!";
hasher.input(data);
// `input` can be called repeatedly and is generic over `AsRef<[u8]>`
hasher.input("String data");
// Note that calling `finalize()` consumes hasher
let hash = hasher.finalize();
println!("Result: {:x}", hash);

However, Digest values do not have an input() method; the correct name of the method is update(), and so the code above (after adding a fn main()) will not compile. Even after that's fixed, trying to compile the code still fails with the following error:

error[E0283]: type annotations needed for `CoreWrapper<CtVariableCoreWrapper<Blake2bVarCore, OutSize>>`
 --> src/main.rs:4:22
  |
4 |     let mut hasher = Blake2b::new();
  |         ----------   ^^^^^^^ cannot infer type for type parameter `OutSize`
  |         |
  |         consider giving `hasher` the explicit type `CoreWrapper<CtVariableCoreWrapper<_, OutSize>>`, where the type parameter `OutSize` is specified
  |
  = note: cannot satisfy `_: ArrayLength<u8>`
  = note: required because of the requirements on the impl of `BlockSizeUser` for `CtVariableCoreWrapper<Blake2bVarCore, _>`

For more information about this error, try `rustc --explain E0283`.
error: could not compile `digest-example` due to previous error
@tarcieri
Copy link
Member

tarcieri commented Aug 8, 2022

Thanks. We should find a way to test this code, possibly using a dummy crate and #[doc = include_str!(...)]

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