Created
July 14, 2012 14:58
-
-
Save iamtakingiteasy/3111728 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
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() + "]" } // can't do this | |
/* but can do this: | |
foo(nest) { | |
let mut result = "foo["; | |
for nest.each() |n| { | |
result += n.to_str(); | |
} | |
result += "]"; | |
result | |
} | |
*/ | |
} | |
} | |
} | |
fn main() { | |
let quxx = foo(~[foo(~[bar])]); | |
println(quxx.to_str()); | |
} | |
~~~~~~~~~~~~~~~~~~~ compilation result ~~~~~~~~~~~~~~~~~~~~~~ | |
user@note ~/soft/mine/rust $ rustc brainfuck.rs && echo done && ./brainfuck | |
brainfuck.rs:13:33: 13:44 error: failed to find an implementation of interface core::to_str::to_str for some_enum | |
brainfuck.rs:13 foo(nest) { "foo[" + nest.to_str() + "]" } // can't do this | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment