Created
January 11, 2019 05:33
-
-
Save DanielJoyce/ec0056ce5d5ee06b988a1d81102a539b to your computer and use it in GitHub Desktop.
Okay, so this is cool....
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
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