You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The below doesn't compile but shows what I have in mind
externcrate sha2;// 0.7.1use sha2::{Sha256,Sha512,Digest};fnperform_hashing<'a>(str_to_hash:&str,hasher:&'a mutSha256) -> &'a [u8]{
hasher.input(str_to_hash.as_bytes());// we will be hashing a lot of strings// can be more efficient compared to hasher re-creation.let a = hasher.result_reset();&a[..]}fnmain(){let my_strings = vec!["hello, world", "helios"];letmut hasher:Sha256 = Digest::new();for string in my_strings {perform_hashing(string,&mut hasher);}}
The text was updated successfully, but these errors were encountered:
Note that the doc tests for the linked example pass:
cargo test --doc
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Doc-tests sha2
running 9 tests
[...]
test src/lib.rs - (line 22) ... ok
test result: ok. 1 passed; 0 failed; 8 ignored; 0 measured; 0 filtered out
The new() method is part of the Digest trait, which you'll need in-scope:
Seems to me that the example on src/sha2/src/lib.rs#L20 cannot be ran, one would run into errors such as
Sha256::new()
not existing.Something like this works for me though:
Am I missing something?
Slightly unrelated but still on documentation, could be related to #86.
Is there an ergonomic way to return a hash given some input?
I could try return a
GenericArray
but that seems to have 2 disadvantages:OutputSize
also seems to go on to add another deptypenum
via ArrayLengthThe below doesn't compile but shows what I have in mind
The text was updated successfully, but these errors were encountered: