Skip to content

Instantly share code, notes, and snippets.

@morimolymoly
Created April 5, 2020 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morimolymoly/51ee0556a4d166a8ce75968f6f0ca0a2 to your computer and use it in GitHub Desktop.
Save morimolymoly/51ee0556a4d166a8ce75968f6f0ca0a2 to your computer and use it in GitHub Desktop.
trait A {
fn fn_a(&self) {
println!("fna");
}
}
trait B {
fn fn_b(&self) {
println!("fnb");
}
}
trait C: A + B {}
struct St1{}
impl A for St1{}
impl B for St1{}
impl C for St1{}
struct St2{}
impl A for St2{}
impl B for St2{}
impl C for St2{}
fn main() {
//let mut st_vec: Vec<Box<dyn A + B>> = Vec::new();
let mut st_vec2: Vec<Box<dyn C>> = Vec::new();
st_vec2.push(Box::new(St1{}));
st_vec2.push(Box::new(St2{}));
for s in st_vec2.iter() {
s.fn_a();
s.fn_b();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment