-
-
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? |
| //! fn fill_bytes(&mut self, dst: &mut [u8]) { | ||
| //! for byte in dst { | ||
| //! let val = self.0; | ||
| //! self.0 = val + 1; | ||
| //! *byte = val; | ||
| //! } | ||
| //! } |
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'd rather we just write todo!() than implement a counting-generator in every single example.
| 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.
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
lemodule is renamed toutilsand now contains the new helper function.The new examples demonstrate implementation of the traits for the most common RNG classes.
TODO: