trait Shine {
fn shine(&self);
}
struct Red {}
impl Shine for Red {
fn shine(&self) {
println!("Reddish shine.")
}
}
struct Blue {}
impl Shine for Blue {
fn shine(&self) {
println!("Blueish shine.")
}
}
struct Green {}
impl Shine for Green {
fn shine(&self) {
println!("Greenish shine.")
}
}
struct ColoredCarsDealership {
red_cars: Vec<Car<Red>>,
blue_cars: Vec<Car<Blue>>,
green_cars: Vec<Car<Green>>,
}
struct Car<C: Shine> {
color: C,
}
impl<C: Shine> Car<C> {
pub fn new(color: C, dealership: &mut ColoredCarsDealership) {
let new_car = Car { color };
// insert(new_car, dealership); <-- How to do this
}
}
Am I thinking the right way?
Link to playground.