1use std::fs::File;
2use std::io::{BufReader, Error as IOError, Read};
3use std::path::PathBuf;
4
5pub(crate) trait Source {
6 type Item;
7 type Error;
8
9 fn load(&self) -> Result<Self::Item, Self::Error>;
10}
11
12pub(crate) struct FileSource {
13 path: PathBuf,
14}
15
16impl FileSource {
17 pub(crate) fn new(path: PathBuf) -> FileSource {
18 FileSource { path }
19 }
20}
21
22impl Source for FileSource {
23 type Item = String;
24 type Error = IOError;
25
26 fn load(&self) -> Result<Self::Item, Self::Error> {
27 let mut reader: BufReader = BufReader::new(inner:File::open(&self.path)?);
28
29 let mut buf: String = String::new();
30 reader.read_to_string(&mut buf)?;
31
32 Ok(buf)
33 }
34}
35