Created
June 20, 2013 03:36
-
-
Save msullivan/5820128 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #[allow(default_methods)] | |
| trait Speak { | |
| fn say(&self, s:&str); | |
| fn hi(&self) { hello(self); } | |
| } | |
| fn hello<S:Speak>(s:&S) { | |
| s.say("hello"); | |
| } | |
| impl Speak for int { | |
| fn say(&self, s:&str) { | |
| println(fmt!("%s: %d", s, *self)); | |
| } | |
| } | |
| impl<T: Speak> Speak for Option<T> { | |
| fn say(&self, s:&str) { | |
| match *self { | |
| None => println(fmt!("%s to nobody", s)), | |
| Some(ref x) => { println("something!"); x.say(s); } | |
| } | |
| } | |
| } | |
| fn main() { | |
| 3.hi(); | |
| Some(3).hi(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment