From f74d121b8e6d87bf27c07b3d53c171000fc74f4e Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 10 Jul 2018 15:49:28 +0100 Subject: Simplify get_template_source() by using fs::read_to_string() --- askama_shared/src/path.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'askama_shared/src/path.rs') diff --git a/askama_shared/src/path.rs b/askama_shared/src/path.rs index 4197376..eff8f29 100644 --- a/askama_shared/src/path.rs +++ b/askama_shared/src/path.rs @@ -1,21 +1,18 @@ use super::Config; -use std::fs::File; -use std::io::Read; +use std::fs; use std::path::{Path, PathBuf}; pub fn get_template_source(tpl_path: &Path) -> String { - let mut f = match File::open(tpl_path) { + match fs::read_to_string(tpl_path) { Err(_) => panic!("unable to open template file '{}'", tpl_path.to_str().unwrap()), - Ok(f) => f, - }; - - let mut s = String::new(); - f.read_to_string(&mut s).unwrap(); - if s.ends_with('\n') { - let _ = s.pop(); + Ok(mut source) => { + if source.ends_with('\n') { + let _ = source.pop(); + } + source + } } - s } pub fn find_template_from_path(path: &str, start_at: Option<&Path>) -> PathBuf { -- cgit