Created
April 5, 2020 17:37
-
-
Save morimolymoly/51ee0556a4d166a8ce75968f6f0ca0a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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