Improve doc on implementing Default and Clone#383
Conversation
|
Looks good to me! |
b6e50ee to
aa3b147
Compare
| /// support optional at the crate level in PRNG libs. | ||
| /// - `Clone`, but only if the clone will have identical output to the original | ||
| /// (i.e. be a true clone), or if the clone would be another handle to the | ||
| /// same generator. |
There was a problem hiding this comment.
I never really got the point of saying this. If you put anything in an Rc<..> type then clone() will copy the reference, not the object — so why even say it?
If you're going to be pedantic like this then you might as well update the next point about Copy too, though I don't see much point.
There was a problem hiding this comment.
I copied it from your comment, but now understand why you left it out. With OsRng in mind I think it starts to make more sense, as that is the same principle but without Rc<..>?
There was a problem hiding this comment.
Sort of. I'm wondering if we should say much about Clone at all now. Maybe just that on normal PRNGs clone should imply identical output? Even that may not make sense given that we might try to make StdRng reseed on clone in the future(?).
There was a problem hiding this comment.
I just reworded it as "Clone if possible"
aa3b147 to
34ebc80
Compare
|
Spelling out my concerns on implementing
I think you mean |
|
Yes, I meant I don't see any reason |
d91e110 to
f6d6fe4
Compare
|
Added a commit to implement |
DefaultDefault and Clone
|
Does it make sense to implement |
I don't care much about the |
| /// [Jitterentropy](http://www.chronox.de/jent.html) version 2.1.0. | ||
| /// | ||
| /// [`OsRng`]: ../os/struct.OsRng.html | ||
| #[derive(Clone)] |
There was a problem hiding this comment.
Don't we at the very least need to clear data_half_used to prevent next_u32 returning the same result from each part?
Otherwise we could simply implement this with JitterRng::new — except that timer might not be the default function.
There was a problem hiding this comment.
Good catch! Glad you are sharp 😄.
| inner: self.inner.clone(), | ||
| reseeder: self.reseeder.clone(), | ||
| threshold: self.threshold, | ||
| bytes_until_reseed: 0, // reseed clone on first use |
6394566 to
a68ec1d
Compare
| data: self.data, | ||
| rounds: self.rounds, | ||
| timer: self.timer, | ||
| mem_prev_index: self.mem_prev_index, |
There was a problem hiding this comment.
Do you think mem_prev_index should be adjusted?
There was a problem hiding this comment.
I think we are okay leaving it as is. They probably have different locations for the memory slice on the stack. Having the same location twice should not make the CPU much better at predicting. And after the first round the values will diverge, as memaccess is called a variable number of times.
|
Okay, I was going to merge, but there are conflicts. |
a68ec1d to
6060f1a
Compare
|
Rebased |
Fixes #378.
cc @newpavlov