-
-
Notifications
You must be signed in to change notification settings - Fork 1
Replace block module with helper functions
#24
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: master
Are you sure you want to change the base?
Conversation
|
What does this look like at the use site? You could update |
|
Motivation regarding
Not a change.
I explained why I didn't want to do this in rust-random/rand#1667. |
See the new doc examples. I wanted to update the implementation crates after I got a confirmation that you approve the new approach.
True. I will edit the OP.
The problem is that the |
|
All potential panics in
|
|
I improved codegen for |
|
I don't want to merge this for two reasons:
Some changes are probably worth keeping. #29 includes some of the unproblematic changes. |
|
I replaced the utility functions with the new I will work on |
|
As I said here:
|
|
As I wrote in previous discussions, I think we should completely remove the block RNG trait since its only use in practice is |
|
In practice though you are just using a closure instead of a trait here. It doesn't make for a cleaner interface. |
Cleanup from rust-random/rand#1692 and #24.
|
This is an implementation detail. Take look at the examples, the code looks pretty clean to me. This approach also makes a bit easier to implement the |
|
Looks like a re-write of the
How is that any different from this? |
dhardy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments only (not a change request since I do not plan to merge this).
I gave two reasons for rejecting this PR above, but here's a third: we don't need to rewrite what already exists.
I attempted to ascertain your goals here in #31, and I think we can hit those same goals without a rewrite of what we already have. Which, given that the current code is decently well proven, is quite significant in my opinion.
Take look at the examples, the code looks pretty clean to me.
Neat examples are not very important. Validation against existing code like the rand repository is much more important.
I think we should completely remove the block RNG trait since its only use in practice is
ReseedingRng.
Opinionated take. What you have produced here is just a cut-down variation on the existing block module. #34 reduces this to just Generator, CryptoGenerator and BlockRng. Effectively, this code is replacing Generator with a closure (not my preference when the flexibility of closures is not required) and dropping CryptoGenerator.
My view is that we should limit changes to the rand_core API to only things which have clear motivation.
IMO it's a wrong stance to have if you intend to release v1.0 in the near future. Your Additionally, this PR makes the API surface of
What are you talking about? I validated the proposed approach in rust-random/rngs#78 and rust-random/rand#1686. They both show clear reduction of total code size. The only problem is performance of If you intend to keep the |
IMO it's the wrong stance to rewrite everything right before stabilisation.
Yes, that's what I'm talking about. Sorry, I missed your updates for some reason.
Closures are just another form of interface, and I find them less neat personally. (Excepting where the closures are actually doing interesting things; not just accessing a field.) Moving My intention actually (as mentioned in #13) is to move everything except what we are already happy to stabilise (maybe just
With future Rust features, yes. I don't think we can bet on those landing in the near future (read: next few years). This is a good argument for keeping the trait out of |
As I wrote before, I would prefer to not stabilize
Yes. But my point is that we don't have to make it "neat". The practice shows that users do not care about the block RNG interface. Implementation of buffering should be nothing more than an implementation detail. The primary reason why we care about exposing the block RNG interface is |
This change allows to remove the
serdefeature and reduce total amount of code in the crate. Additionally, the helper block functions now store the cursor position in the first buffer value, which allows us to remove the separateindexfield.The new examples demonstrate implementation of the traits for the most common RNG classes.
TODO: