Skip to content

Instantly share code, notes, and snippets.

@zslayton
Created December 8, 2013 20:25
Show Gist options
  • Save zslayton/7863380 to your computer and use it in GitHub Desktop.
Save zslayton/7863380 to your computer and use it in GitHub Desktop.
extern mod extra;
use extra::treemap::TreeMap;
use extra::json::{Json,Object};
enum NestedSearchError {
NoSuchAncestor(~str),
NoSuchKey,
TypeMismatch
}
trait NestableObject {
fn find_nested(&self, key: &~str) -> Result<Json, NestedSearchError>;
}
impl NestableObject for Object {
fn find_nested(&self, key: &~str) -> Result<Json, NestedSearchError> {
Err(NoSuchKey)
}
}
fn main(){
let obj = Object(~TreeMap::<~str, Json>::new());
match obj.find_nested(&~"dog") {
NoSuchKey => println("Couldn't find that key."),
_ => println("Unexpected result.")
}
}
/*
simplejson.rs:25:7: 25:33 error: type `extra::json::Json` does not implement any method in scope named `find_nested`
simplejson.rs:25 match obj.find_nested(&~"dog") {
^~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /home/zslayton/rust/src/libsyntax/diagnostic.rs:102
task '<main>' failed at 'explicit failure', /home/zslayton/rust/src/librustc/lib.rs:393
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment