You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#1369 has brought up a use for set_block_pos() and get_block_pos() for rand_chacha.
In implementing it for chacha20 with BlockRng, there is a minor issue with the API without using a new trait. The methods seem like they should belong on the core instead of the rng, but when implementing just those 2 methods, it results in these calls:
// this is essentially how the Rng is defined in this scenariopubstructChaCha20Rng{pubrng:BlockRng<ChaCha20Core>,}letmut rng = ChaCha20Rng::from_entropy();
rng.rng.core.set_block_pos(x);
rng.rng.core.get_block_pos();
This could be simplified by adding a ChaCha20Rng::get_core_mut() method, down to:
rng.get_core_mut().set_block_pos(x);
But now there are even more characters to type.
There is also a potential issue regarding set_block_pos() located on the core. The following code will fail because changing the block_pos on the core will not affect the index of the rng. So we will need to decide if that is okay or not:
letmut rng = ChaCha20Rng::from_entropy();
rng.core.set_block_pos(5);let a = rng.next_u32();
rng.core.set_block_pos(5);let b = rng.next_u32();// this would failassert_eq!(a, b);
A SeekableRng trait might suffice, allowing for a shorter method call, and it could also handle the above issue depending on if that is an issue that needs to be fixed.
Feature request
I don't know if it would be possible to make a simplified call such as this:
But it seems like for that method to be called that way, SeekableRng would need to be implemented for BlockRng if the rng is a wrapper around it. The method does not need to be called that way though. I personally don't mind whether it is on the rng or the core, but it just seems like something that would go on the core.
structChaCha20Rng(BlockRng<ChaCha20Core>);implChaCha20Rng{fnset_block_pos(x:_){self.0.core.set_block_pos(x);self.0.reset();// or generate_and_set(index)}}
This should be enough for a == b. I don't think we need any impls directly on BlockRng.
Background
#1369 has brought up a use for
set_block_pos()
andget_block_pos()
forrand_chacha
.In implementing it for
chacha20
withBlockRng
, there is a minor issue with the API without using a new trait. The methods seem like they should belong on thecore
instead of therng
, but when implementing just those 2 methods, it results in these calls:This could be simplified by adding a
ChaCha20Rng::get_core_mut()
method, down to:But now there are even more characters to type.
There is also a potential issue regarding
set_block_pos()
located on thecore
. The following code will fail because changing theblock_pos
on thecore
will not affect theindex
of therng
. So we will need to decide if that is okay or not:A
SeekableRng
trait might suffice, allowing for a shorter method call, and it could also handle the above issue depending on if that is an issue that needs to be fixed.Feature request
I don't know if it would be possible to make a simplified call such as this:
But it seems like for that method to be called that way,
SeekableRng
would need to be implemented forBlockRng
if the rng is a wrapper around it. The method does not need to be called that way though. I personally don't mind whether it is on the rng or the core, but it just seems like something that would go on the core.Proposed trait definition:
The text was updated successfully, but these errors were encountered: