Created
January 19, 2022 09:54
-
-
Save xxxxxion/ba438aedef23091256624dc84c44dff7 to your computer and use it in GitHub Desktop.
rust generics gist
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 SomeTrait { | |
fn display_trait(&mut self) { | |
println!("SomeTrait display_trait() !!!"); | |
} | |
} | |
trait AnotherTrait { | |
fn show_trait(&mut self) { | |
println!("Another trait show_trait() !!!"); | |
} | |
} | |
struct Test<T> { | |
val: T, | |
} | |
impl<T> SomeTrait for Test<T> {} | |
impl<T> AnotherTrait for Test<T> {} | |
struct App<T> | |
where | |
T: SomeTrait, | |
{ | |
var: Vec<T>, | |
} | |
fn main() { | |
let test_obj = Test { val: 32 }; | |
let vec_of_obj = vec![test_obj]; | |
let mut app = App { var: vec_of_obj }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment