Skip to content

Instantly share code, notes, and snippets.

@DanielJoyce
Created January 11, 2019 05:33
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 DanielJoyce/ec0056ce5d5ee06b988a1d81102a539b to your computer and use it in GitHub Desktop.
Save DanielJoyce/ec0056ce5d5ee06b988a1d81102a539b to your computer and use it in GitHub Desktop.
Okay, so this is cool....
pub struct Foo {
x: usize
}
pub struct Baz {}
pub trait Derp<Foo> {
fn foo_it(&self);
}
impl Derp<Foo> for Foo {
fn foo_it(&self){
println!("{}", self.x)
}
}
impl Derp<Foo> for Baz {
fn foo_it(&self){
println!("OINK");
}
}
pub trait Bar: Derp<Foo> {
fn do_other_thing_with_foo(&mut self) {
self.foo_it();
self.foo_it();
}
}
impl<T> Bar for T where T: Derp<Foo> {}
fn main() {
let mut x = Foo{x:123};
x.do_other_thing_with_foo();
let mut z = Baz{};
z.do_other_thing_with_foo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment