Skip to content

Instantly share code, notes, and snippets.

@SiegeLord
Created July 6, 2013 15:50
Show Gist options
  • Save SiegeLord/5940286 to your computer and use it in GitHub Desktop.
Save SiegeLord/5940286 to your computer and use it in GitHub Desktop.
Trait object
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