Skip to content

Instantly share code, notes, and snippets.

@sinistersnare
Created May 9, 2014 20:50
Show Gist options
  • Save sinistersnare/b656e39480372606edb5 to your computer and use it in GitHub Desktop.
Save sinistersnare/b656e39480372606edb5 to your computer and use it in GitHub Desktop.
Multiple Traits per impl block in Rust
trait MyFirstTrait {
fn my_first_func() -> ();
}
trait MySecondTrait {
fn my_second_func() -> ();
fn my_third_func() -> ();
}
struct MyStruct;
impl MyFirstTrait, MySecondTrait for MyStruct { //the RFC will allow this
fn my_first_func() -> () { println!("The first function!") }
fn my_second_func() -> () { println!("The second function!") }
fn my_third_func() -> () { println!("The third function!") }
}
//that impl would just be syntactic sugar more or less for:
impl MyFirstTrait for MyStruct {
fn my_first_func() -> () { println!("The first function!") }
}
impl MySecondTrait for MyStruct {
fn my_second_func() -> () { println!("The second function!") }
fn my_third_func() -> () { println!("The third function!") }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment