diff options
Diffstat (limited to 'vendor/handlebars/src/sources.rs')
-rw-r--r-- | vendor/handlebars/src/sources.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/handlebars/src/sources.rs b/vendor/handlebars/src/sources.rs new file mode 100644 index 000000000..8c8b2ba57 --- /dev/null +++ b/vendor/handlebars/src/sources.rs @@ -0,0 +1,34 @@ +use std::fs::File; +use std::io::{BufReader, Error as IOError, Read}; +use std::path::PathBuf; + +pub(crate) trait Source { + type Item; + type Error; + + fn load(&self) -> Result<Self::Item, Self::Error>; +} + +pub(crate) struct FileSource { + path: PathBuf, +} + +impl FileSource { + pub(crate) fn new(path: PathBuf) -> FileSource { + FileSource { path } + } +} + +impl Source for FileSource { + type Item = String; + type Error = IOError; + + fn load(&self) -> Result<Self::Item, Self::Error> { + let mut reader = BufReader::new(File::open(&self.path)?); + + let mut buf = String::new(); + reader.read_to_string(&mut buf)?; + + Ok(buf) + } +} |