Skip to content

Instantly share code, notes, and snippets.

@iamtakingiteasy
Created July 15, 2012 15:05
Show Gist options
  • Save iamtakingiteasy/3117337 to your computer and use it in GitHub Desktop.
Save iamtakingiteasy/3117337 to your computer and use it in GitHub Desktop.
user@note ~/soft/mine/rust $ rustc example.rs && ./example
example.rs:13:32: 13:43 error: failed to find an implementation of interface core::to_str::to_str for some_enum
example.rs:13 foo(nest) { "foo" + nest.to_str() }
^~~~~~~~~~~
import io::*;
import to_str::*;
enum some_enum {
foo(~[some_enum]),
bar
}
impl to_str for some_enum {
fn to_str() -> str {
alt self {
bar { "bar" }
foo(nest) { "foo" + nest.to_str() }
}
}
}
// working, but not as neat
/*
impl to_str for some_enum {
fn to_str() -> str {
alt self {
bar { "bar" }
foo(nest) { "foo" + nest.map(|x| { x.to_str() }).to_str() }
}
}
}
*/
fn main() {
println(foo(~[bar,bar,bar]).to_str());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment