Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMake PRNGs implement Clone instead of Copy #20199
Conversation
rust-highfive
assigned
pcwalton
Dec 24, 2014
This comment has been minimized.
This comment has been minimized.
|
r? @pcwalton (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I agree with @thestinger here. It is somewhat of a footgun if you accidentally copy your RNG, but |
This comment has been minimized.
This comment has been minimized.
|
It’s a fair point and, honestly, I can’t think of counter-argument to that… |
nagisa
closed this
Jan 2, 2015
This comment has been minimized.
This comment has been minimized.
|
I'm not sure how much sense it makes to use most RNGs with In any case, it would be good to have these structs implement (It might be good to have some tests that check that |
tbu-
referenced
this pull request
in tbu-/collect-rs
Jan 7, 2015
This comment has been minimized.
This comment has been minimized.
|
i likewise agree with @huonw that not implementing |
nagisa commentedDec 24, 2014
Remove derivations of
Copytrait fromChaChaRng,IsaacRng,Isaac64Rngand
StdRngand implement theClonetrait instead.Copying is an implicit operation and the copy shares its internal state with
the original generator. This means the the two generators will yield exactly
the same sequence of values. This behaviour is considerably easy to trigger
by, for example, passing the generator by value to a function.
Clonetrait, on the other hand, does no implicit copying. The user will onlybe able to either move the generator or ask for a copy explicitly, via the
clonemethod.The only downside to this patch is the fact that the implementations of
Clone::clonemethods do not optimise down to a single memcpy, like thederived
Copyimplementations did.Although the
Copyimplementations of these random number generators aresuspected to not be used much, this is a [breaking-change].
Fixes #20170.