diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 35 |
1 files changed, 22 insertions, 13 deletions
@@ -47,14 +47,16 @@ pub struct ModelEntry { pub markdown: String, } -pub fn parse_metadata(raw: String) -> Result<ModelMetadata,String> { +pub fn parse_metadata(raw: String) -> Result<ModelMetadata, String> { let root = toml::Parser::new(&raw).parse().unwrap(); let model = root.get("model") .expect("missing 'model' section") - .as_table().unwrap(); + .as_table() + .unwrap(); let variables = root.get("variables") .expect("missing 'variables' section") - .as_table().unwrap(); + .as_table() + .unwrap(); let mut vars = vec![]; for (slug, info) in variables { let info = info.as_table().unwrap(); @@ -82,24 +84,30 @@ pub fn parse_metadata(raw: String) -> Result<ModelMetadata,String> { }) } -pub fn load_model_entry(p: &Path) -> Result<ModelEntry,String> { +pub fn load_model_entry(p: &Path) -> Result<ModelEntry, String> { debug!("Attempting to load model from: {:?}", p); let ast = { let mut s = String::new(); - try!(File::open(p.join("model.modelica")).and_then(|mut f| f.read_to_string(&mut s)).map_err(|e| e.to_string())); + try!(File::open(p.join("model.modelica")) + .and_then(|mut f| f.read_to_string(&mut s)) + .map_err(|e| e.to_string())); try!(modelica_parser::parser::parse_model(&s).map_err(|e| format!("{:?}", e))) }; let metadata = { let mut s = String::new(); - try!(File::open(p.join("metadata.toml")).and_then(|mut f| f.read_to_string(&mut s)).map_err(|e| e.to_string())); + try!(File::open(p.join("metadata.toml")) + .and_then(|mut f| f.read_to_string(&mut s)) + .map_err(|e| e.to_string())); parse_metadata(s).unwrap() }; let markdown = { let mut s = String::new(); - try!(File::open(p.join("page.md")).and_then(|mut f| f.read_to_string(&mut s)).map_err(|e| e.to_string())); + try!(File::open(p.join("page.md")) + .and_then(|mut f| f.read_to_string(&mut s)) + .map_err(|e| e.to_string())); s }; @@ -112,12 +120,13 @@ pub fn load_model_entry(p: &Path) -> Result<ModelEntry,String> { pub fn search_models(p: &Path) -> Vec<String> { if fs::metadata(p).unwrap().is_dir() { - fs::read_dir(p).unwrap() - .map(|x| x.unwrap()) - .filter(|x| x.metadata().unwrap().is_dir()) - .filter(|x| x.path().join("model.modelica").exists()) - .map(|x| x.path().to_string_lossy().to_string()) - .collect() + fs::read_dir(p) + .unwrap() + .map(|x| x.unwrap()) + .filter(|x| x.metadata().unwrap().is_dir()) + .filter(|x| x.path().join("model.modelica").exists()) + .map(|x| x.path().to_string_lossy().to_string()) + .collect() } else { vec![] } |