I have the following code
extern crate rand;
use rand::Rng;
pub struct Randomizer {
rand: Box,
}
impl Randomizer {
fn new() -> Self {
I also want to post the answer, that one way to deal with this situation is
fn with_rng(rng: &TRand) -> Self {
let r = Box::new(*rng);
Randomizer { rand: r }
}
Rust's monomorphism will create the necessary implementation of with_rng
replacing TRand
by a concrete sized type. In addition, you may add a trait bound requiring TRand
to be Sized
.