Created
July 15, 2012 15:05
-
-
Save iamtakingiteasy/3117337 to your computer and use it in GitHub Desktop.
This file contains 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
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() } | |
^~~~~~~~~~~ |
This file contains 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
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