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

Tracking Issue for Hasher::{write_str, write_length_prefix} (feature(hasher_prefixfree_extras)) #96762

Open
1 of 3 tasks
Tracked by #20
scottmcm opened this issue May 6, 2022 · 1 comment
Open
1 of 3 tasks
Tracked by #20
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented May 6, 2022

Feature gate: #![feature(hasher_prefixfree_extras)]

This is a tracking issue for the new provided methods on Hasher added to fix #94026

  • write_str lets the hasher customize how it works with str, so it can use the b'\xFF' trick if it's byte-wise, or a different approach if it does chunked rounds.
  • write_length_prefix gives an obvious choice when implementing Hash for collections (like VecDeque) which can't just use the slice hash, and allows the hasher to optimize how best to represent the length.

Public API

// core::hash

pub trait Hasher {
    // ... existing stuff ...
    fn write_length_prefix(&mut self, len: usize);
    fn write_str(&mut self, s: &str);
}

Steps / History

Unresolved Questions

  • What should the write_str provided implementation be? It was added matching the previous impl Hash for str behaviour to get in without breaking hash checks (like the one in cargo), but that's not always prefix-free (it depends on the round strategy), so there's an argument that a different implementation would be better.
@scottmcm scottmcm added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels May 6, 2022
@tgross35
Copy link
Contributor

Possible bikeshed: it was indirectly mentioned in passing here that this is the only std API that comes up when you search length. The rest all seem to use len

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants