libsyntax: Implement the impl Trait for Type syntax

This commit is contained in:
Patrick Walton 2013-01-29 11:14:53 -08:00
parent 1b021d5868
commit 4ead38bae7
2 changed files with 49 additions and 6 deletions

View file

@ -0,0 +1,26 @@
struct Thingy {
x: int,
y: int
}
impl ToStr for Thingy {
pure fn to_str() -> ~str {
fmt!("{ x: %d, y: %d }", self.x, self.y)
}
}
struct PolymorphicThingy<T> {
x: T
}
impl<T:ToStr> ToStr for PolymorphicThingy<T> {
pure fn to_str() -> ~str {
self.x.to_str()
}
}
fn main() {
io::println(Thingy { x: 1, y: 2 }.to_str());
io::println(PolymorphicThingy { x: Thingy { x: 1, y: 2 } }.to_str());
}