4 fn say(&self, s:&str) -> String;
5 fn hi(&self) -> String { hello(self) }
8 fn hello<S:Speak>(s:&S) -> String{
12 impl Speak for isize {
13 fn say(&self, s:&str) -> String {
14 format!("{}: {}", s, *self)
18 impl<T: Speak> Speak for Option<T> {
19 fn say(&self, s:&str) -> String {
21 None => format!("{} - none", s),
22 Some(ref x) => { format!("something!{}", x.say(s)) }
29 assert_eq!(3.hi(), "hello: 3".to_string());
30 assert_eq!(Some(Some(3)).hi(),
31 "something!something!hello: 3".to_string());
32 assert_eq!(None::<isize>.hi(), "hello - none".to_string());
34 assert_eq!(Some(None::<isize>).hi(), "something!hello - none".to_string());
35 assert_eq!(Some(3).hi(), "something!hello: 3".to_string());