Skip to content

Instantly share code, notes, and snippets.

@fxposter
Created January 15, 2014 15:06
Show Gist options
  • Save fxposter/8437918 to your computer and use it in GitHub Desktop.
Save fxposter/8437918 to your computer and use it in GitHub Desktop.
struct S;
impl S {
fn a(&self) {
println!("a");
}
fn b(&self) {
println!("b");
}
}
trait T {
fn b(&self);
fn a(&self);
}
impl T for S {
fn a(&self) {
println!("A");
self.b();
}
fn b(&self) {
println!("B");
self.a();
}
}
fn test_trait(t: &T) {
t.a();
}
fn main() {
let s = S;
test_trait(&s);
}
@fxposter
Copy link
Author

$ rustc test.rs && ./test
A
b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment