Skip to content

Instantly share code, notes, and snippets.

@xxxxxion
Created January 19, 2022 09:54
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 xxxxxion/ba438aedef23091256624dc84c44dff7 to your computer and use it in GitHub Desktop.
Save xxxxxion/ba438aedef23091256624dc84c44dff7 to your computer and use it in GitHub Desktop.
rust generics gist
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