Hello.
I have a question about language features.
I'm particularly interested in dereferencing for Box.
Is it possible to write a generalized structure that can store "an object that implements trait" or Box< an object that implements trait>. Example below:
trait Say
{
fn say(&self);
}
struct Dog
{}
struct Human
{}
impl Say for Dog
{
fn say(&self)
{
println!("Woof!");
}
}
impl Say for Human
{
fn say(&self)
{
println!("Hello!");
}
}
struct House<S>
where S: Say
{
s: S
}
impl<S> House<S>
where S: Say
{
fn new(s: S)->House<S>
{
House{s}
}
fn habitant_say(&self)
{
self.s.say();
}
}
fn main() {
let dog=Dog{};
let h=House::new(dog);
//let dog_in_box=Box::new(dog);
//let h=House::new(dog_in_box);
h.habitant_say();
}
What do I need to change so that I can create House< Dog>, House< Human> .... as well as House<Box< Dog>>, House<Box< Human>> ....
Or is it impossible?