-
Notifications
You must be signed in to change notification settings - Fork 14k
Add a deterministic constructor for RandomState
#135578
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
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jhpratt (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
Can you give an example where this appeared as a problem? |
d6af4c9 to
ee7f783
Compare
|
Thank you for the PR! This PR contains a public library API change, which should follow the proper process of creating an ACP first: https://std-dev-guide.rust-lang.org/development/feature-lifecycle.html |
|
Thanks for pointing me to the ACP process. I've opened rust-lang/libs-team#523. (Side note: It would be awesome to have a master flow chart that guides through the process for any possible Rust contribution scenario. I missed the ACP process because it wasn't mentioned in the "Library Tracking Issue" template.) |
RandomStateis the default hasher forstd::collections::{HashMap, HashSet}. Today, the only way to construct aRandomStateis viaRandomState:new(), which generates fresh random keys on every call. That's a good default for security, but it makes testing challenging, because test failures might not be reproducible due to nondeterministic behavior.Although in principle it is possible to use other deterministic hashers, there are libraries which have hash collections with
RandomStatehardcoded in their public interface. For example, see aws_sdk_dynamodb (and this discussion).This change adds a new constructor for
RandomStatethat returns a fixed value, which makes it possible for programs to behave deterministically even if they are locked in toRandomStatefor hashing.ACP: rust-lang/libs-team#523