-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
How to migrate away from Rand trait (Upgrading 0.4 -> 0.6) #694
Comments
IIRC Rand 0.5 had a transitional implementation of In theory we could add optional compatibility wrappers for 0.4 over 0.5 and 0.5 over 0.6, then let you use 0.6 for your library while users can still use older Rand releases, but that's a lot of work. Effectively this means that migrating from Rand 0.4 to 0.6 is a breaking release for your library, hence you must bump the version (including items from an unstable crate into the API of your crate makes it impossible to promise stability in your API). Alternatively you can copy the As for coding the equivalent type restriction using Rand 0.6, you can't without making a similar trait (implemented |
It would be fine to break to a certain degree, but the functionality really should be all kept in this single trait ideally. This is the code I am trying to migrate: https://github.com/zkcrypto/ff/blob/master/src/lib.rs#L19 maybe you have some ideas on how this could be done in a good way. |
What do you use this for? Obviously to sample a random instance, but semantically what does this mean and why does it happen (only testing, or perhaps IV generation)? |
This is used for mainly two purposes
|
Also these are implemented for "higher level fields" like here: https://github.com/zkcrypto/pairing/blob/master/src/bls12_381/fq2.rs#L59-L66 in the sense that these are combinations of the simpler forms, that rely on the coordinates being generated through this |
If you want to stay with the same style, then I would suggest making your own version of the The I would suggest you do something like the following (or possibly remove the method and use it only as a marker trait): trait UniformRandom {
fn sample<R: Rng + ?Sized>(rng: R) -> Self;
}
impl<T> UniformRandom for T where Standard: Distribution<T> {
fn sample<R: Rng + ?Sized>(rng: R) -> Self {
rand::distribution::Standard.sample(rng)
}
} |
This makes sense, and yes I think random variables is right for the usage here. I will try this out and report back if this covers all the use cases. |
@dignifiedquire I'll assume that solved your problem? |
Did you resolve this? It's clear We could introduce a specific trait like @dhardy suggests, except probably use standard in the name.
I'm though curious why rand lacks some more general trait to serve this purpose, like say
It'd play the same roll for |
I haven’t looked into it again, but it is on my todo list. |
I am trying to upgrade a dependency of mine which has a trait that looks like this:
Now I understand that
Rand
was effectively replaced byStandard: Distribution<T>
. The issue though is that I can not use this to easily add this is into this trait, as only addingDistribution<Self>
does not get satisfied if I only implementDistribution<T> for Standard
.So the question is how can I migrate this code, without breaking all of the dependent crates?
The text was updated successfully, but these errors were encountered: