blob: 8c8b2ba570e08fcfbc87705571be4a7353adb89d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
}
}
|