Created
July 6, 2013 15:50
-
-
Save SiegeLord/5940286 to your computer and use it in GitHub Desktop.
Trait object
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
impl<'self> ToStr for ~std::to_str::ToStr | |
{ | |
fn to_str(&self) -> ~str | |
{ | |
self.to_str(); | |
} | |
} | |
fn test<T : ToStr>(a : T) | |
{ | |
println(a.to_str()); | |
} | |
fn main() | |
{ | |
let x = ~1i; let t = x as ~ToStr; test(t); | |
} | |
/* | |
test.rs:1:0: 7:1 error: cannot provide an extension implementation for a trait not defined in this crate | |
test.rs:1 impl<'self> ToStr for ~std::to_str::ToStr | |
test.rs:2 { | |
test.rs:3 fn to_str(&self) -> ~str | |
test.rs:4 { | |
test.rs:5 self.to_str(); | |
test.rs:6 } | |
... | |
error: aborting due to previous error | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment