Skip to content

Instantly share code, notes, and snippets.

@Centril
Created February 23, 2015 20:27
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 Centril/2c82c17007ad44903535 to your computer and use it in GitHub Desktop.
Save Centril/2c82c17007ad44903535 to your computer and use it in GitHub Desktop.
Trait & struct have the same name for a method
fn main() {
let b = B;
(&b as &A).a();
}
trait A {
fn a( &self );
}
struct B;
impl B {
fn a( &self ) {
println!( "World!");
}
}
impl A for B {
fn a( &self ) {
println!( "Hello" );
self.a();
}
}
@Centril
Copy link
Author

Centril commented Feb 23, 2015

Prints:

Hello
World!

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