2013-01-29 13:14:53 -06:00
|
|
|
struct Thingy {
|
|
|
|
x: int,
|
|
|
|
y: int
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToStr for Thingy {
|
2013-03-22 13:23:21 -05:00
|
|
|
fn to_str(&self) -> ~str {
|
2013-01-29 13:14:53 -06:00
|
|
|
fmt!("{ x: %d, y: %d }", self.x, self.y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PolymorphicThingy<T> {
|
|
|
|
x: T
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T:ToStr> ToStr for PolymorphicThingy<T> {
|
2013-03-22 13:23:21 -05:00
|
|
|
fn to_str(&self) -> ~str {
|
2013-01-29 13:14:53 -06:00
|
|
|
self.x.to_str()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2013-01-29 13:14:53 -06:00
|
|
|
io::println(Thingy { x: 1, y: 2 }.to_str());
|
|
|
|
io::println(PolymorphicThingy { x: Thingy { x: 1, y: 2 } }.to_str());
|
|
|
|
}
|