diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-07-10 15:49:28 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-07-10 15:49:28 +0100 |
commit | f74d121b8e6d87bf27c07b3d53c171000fc74f4e (patch) | |
tree | c9cd869f9aafc979127d4061089dda1d82b16414 | |
parent | ab9891f9c5291b8afb2f052d156780089efd99cd (diff) | |
download | askama-f74d121b8e6d87bf27c07b3d53c171000fc74f4e.tar.gz askama-f74d121b8e6d87bf27c07b3d53c171000fc74f4e.tar.bz2 askama-f74d121b8e6d87bf27c07b3d53c171000fc74f4e.zip |
Simplify get_template_source() by using fs::read_to_string()
-rw-r--r-- | askama_shared/src/path.rs | 19 |
1 files changed, 8 insertions, 11 deletions
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 { |