Skip to content

Instantly share code, notes, and snippets.

@iamtakingiteasy
Created July 14, 2012 14:58
Show Gist options
  • Save iamtakingiteasy/3111728 to your computer and use it in GitHub Desktop.
Save iamtakingiteasy/3111728 to your computer and use it in GitHub Desktop.
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