Last active
August 29, 2015 13:56
-
-
Save karl-zylinski/8792212 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
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