diff options
Diffstat (limited to 'src/works/mod.rs')
| -rw-r--r-- | src/works/mod.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/works/mod.rs b/src/works/mod.rs index f062565..cfd302d 100644 --- a/src/works/mod.rs +++ b/src/works/mod.rs @@ -1,18 +1,16 @@ +use anyhow::Result; use serde::{Deserialize, Serialize}; pub mod stories; pub trait Works: for<'a> Deserialize<'a> + Serialize { - fn new_from_file(file: std::fs::File) -> Self { - match serde_json::from_reader(std::io::BufReader::new(file)) { - Ok(work) => work, - Err(err) => panic!("Trying to create work from JSON File - {:?}", err), - } + fn new_from_file(file: std::fs::File) -> Result<Self> { + Ok(serde_json::from_reader(std::io::BufReader::new(file))?) } - fn create_tera_context(&self) -> tera::Context { + fn create_tera_context(&self) -> Result<tera::Context> { let mut context = tera::Context::new(); context.insert("works", &self); - context + Ok(context) } } |
