Skip to content

Instantly share code, notes, and snippets.

@karl-zylinski
Last active August 29, 2015 13:56
Show Gist options
  • Save karl-zylinski/8792212 to your computer and use it in GitHub Desktop.
Save karl-zylinski/8792212 to your computer and use it in GitHub Desktop.
pub fn load_level(&mut self, filename: ~str) -> ~[~Entity] {
let level_json_str = File::open(&Path::new(filename)).read_to_end();
let level_json = match json::from_str(level_json_str.to_str()) {
Ok(json) => json,
Err(e) => fail!("Failed to load level.")
};
let root_json = match level_json { json::Object(~o) => Some(o), _ => None};
let entities_json = root_json.as_ref().map_or(~[], |&j|
j.find(&~"entities").as_ref().map_or(~[], |&e| match e { json::List(l) => l, _ => ~[]})
);
// more stuff
}
Gives me:
resource_store.rs:42:70: 42:83 error: mismatched types: expected `&extra::json::
Json` but found an enum or structure pattern
resource_store.rs:42 j.find(&~"entities").as_ref().map_or(~[], |&e|
match e { json::List(l) => l, _ => ~[]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment