Hi,
I have an enum of two variants, each holding a vector of items implementing a common trait S
. I’d like to write a method that returns an iterator on this vector, no matter which variant the enum is.
The code is (I put some ???
where I don’t know what to write):
trait S {
fn x(&self);
}
struct S1 {}
impl S for S1{
fn x(&self) {}
}
struct S2 {}
impl S for S2{
fn x(&self) {}
}
enum Enum {
One(Vec<S1>),
Other(Vec<S2>),
}
fn iterate_on_enum(e: &Enum) -> ??? {
match e {
&Enum::One(ref s1s) => s1s.iter().map(|x| x as &S),
&Enum::Other(ref s2s) => s2s.iter().map(|x| x as &S),
}
}
fn main() {
}
It seems to me that I shall be able to return an iterator return trait objects, but I didn’t succeed so far in getting something to compile… Any help is appreciated