-
-
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
| } | ||
|
|
||
| /// Create new block buffer. | ||
| pub fn new_buffer<W: Word, const N: usize>() -> [W; N] { |
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.
One minor disadvantage of using the Word trait to de-duplicate code is that we can not currently mark this function const. Since this function i intended to be used in SeedableRng implementations it does not matter much, plus users can vendor the implementation into their const fn if necessary.
|
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 |
It's fine to put those in a new
Isn't the best validation of a proof-of-concept API to use it? |
| let pos = buf[0].into_usize(); | ||
| match buf.get(pos) { |
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.
What if pos == 0? It looks like this shouldn't happen, but I'd prefer it be obvious to the compiler and reader that this cannot return the position counter.
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.
Would be debug_assert sufficient for that?
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.
I don't know: does it affect optimization?
I really do not want to introduce two separate utility modules. I returned the
I did use them in the examples. I plan to update |
Better to punt the issue to a new PR than to worry overly about it here. More important that this PR is easy to review.
Yes, but examples don't always match up with real usage, so I strongly prefer seeing a new API in a real use-case than just in an example. Doc examples are also harder to review (no highlighting without building docs). |
Co-authored-by: Diggory Hardy <git@dhardy.name>
|
The approach looks broadly okay, not losing much from our previous code. But I cannot approve it without running benchmarks on actual block RNGs, so it does need some downstream implementation before this PR can be approved. |
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: