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 for hasher states could use a reference to the Digest trait #441

Open
izik1 opened this issue Dec 13, 2022 · 5 comments
Open

docs for hasher states could use a reference to the Digest trait #441

izik1 opened this issue Dec 13, 2022 · 5 comments

Comments

@izik1
Copy link

izik1 commented Dec 13, 2022

For someone new to the ecosystem it might be hard to tell how to use a... For example, sha3::Keccak256 (https://docs.rs/sha3/latest/sha3/type.Keccak256.html), it's just a type alias with no real info about what it is (other than some nebulous "hasher state") or how to use it. I'd recommend linking to the Digest trait in the docs as a way of explaining "how to use it"

Additionally (if I should move this to a separate issue, let me know and I will do so) I would recommend an example specifically showing how to sha3::Keccak256::digest(b"a message") in one go. Finally, the example(s) that use update should add more than one message. This would be so that show new user why you would use new and then update rather than digest ("because you can add more than one thing").

I would be willing to create the examples / documentation if this would be agreeable

@newpavlov
Copy link
Member

newpavlov commented Dec 16, 2022

Yes, we will appreciate documentation improvement PRs.

@jselig-rigetti
Copy link

Related, I couldn't get https://github.com/RustCrypto/hashes?tab=readme-ov-file#examples working correctly, had to use the following:

use sha2::{Sha256, Digest};

// from the example
// no such associated item (E0599)
let digest = Sha256::digest(b"hello");

// my usage
// this works
let digest = <Sha256 as Digest>::digest(b"hello");

@tarcieri
Copy link
Member

@jselig-rigetti works fine here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=67a52089d26fccb4f956fc397079b343

It's possible you have another trait in scope which defines a digest method and thus requires you disambiguate

@newpavlov
Copy link
Member

@jselig-rigetti
Are you sure it's not this rust-analyzer issue?

@jselig-rigetti
Copy link

Ah, it could have been, thanks for the link!

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

No branches or pull requests

4 participants