From 3dd29b9f15720338d8e1face240d86dd1b6ed50e Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 10 Jul 2018 14:38:48 +0100 Subject: Simplify handling of file open errors --- askama_shared/src/path.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'askama_shared/src/path.rs') diff --git a/askama_shared/src/path.rs b/askama_shared/src/path.rs index 8152b5d..6468b91 100644 --- a/askama_shared/src/path.rs +++ b/askama_shared/src/path.rs @@ -17,13 +17,12 @@ pub fn get_template_source(tpl_path: &Path) -> String { "template file '{}' does not exist", tpl_path.to_str().unwrap() )); + let mut f = match File::open(&path) { - Err(_) => { - let msg = format!("unable to open template file '{}'", &path.to_str().unwrap()); - panic!(msg) - } + Err(_) => panic!("unable to open template file '{}'", &path.to_str().unwrap()), Ok(f) => f, }; + let mut s = String::new(); f.read_to_string(&mut s).unwrap(); if s.ends_with('\n') { -- cgit