pub trait GenerateRand {
// Required method
fn generate<R: Random + ?Sized>(rand: &mut R) -> Self;
}
Expand description
This trait is used by Random::gen()
as a generic function to create a random value for any type which implements it.
I try to give by default implementations for all the types in libcore, including arrays and tuples, if anything is missing please raise the issue.
You can implement this for any of your types.
§Examples
use random_trait::{Random, GenerateRand};
struct MyStuff{
a: u64,
b: char,
}
impl GenerateRand for MyStuff {
fn generate<R: Random + ?Sized>(rand: &mut R) -> Self {
MyStuff {a: rand.gen(), b: rand.gen() }
}
}
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.