libsyntax: Implement the impl Trait for Type syntax
This commit is contained in:
parent
1b021d5868
commit
4ead38bae7
2 changed files with 49 additions and 6 deletions
26
src/test/run-pass/new-impl-syntax.rs
Normal file
26
src/test/run-pass/new-impl-syntax.rs
Normal 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());
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue