Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tamer/src/fs.rs23
-rw-r--r--tamer/src/ld/poc.rs5
2 files changed, 24 insertions, 4 deletions
diff --git a/tamer/src/fs.rs b/tamer/src/fs.rs
index 0471835..ede456a 100644
--- a/tamer/src/fs.rs
+++ b/tamer/src/fs.rs
@@ -41,7 +41,7 @@ use std::collections::HashSet;
use std::ffi::OsString;
use std::fs;
use std::hash::BuildHasher;
-use std::io::Result;
+use std::io::{BufReader, Read, Result};
use std::path::{Path, PathBuf};
/// A file.
@@ -58,6 +58,13 @@ impl File for fs::File {
}
}
+impl<F: File + Read> File for BufReader<F> {
+ /// Open the file at `path` and construct a [`BufReader`] from it.
+ fn open<P: AsRef<Path>>(path: P) -> Result<Self> {
+ Ok(BufReader::new(F::open(path)?))
+ }
+}
+
pub struct CanonicalFile<F: File>(PathBuf, F);
impl<F: File> Into<(PathBuf, F)> for CanonicalFile<F> {
@@ -178,6 +185,20 @@ mod test {
}
}
+ impl Read for DummyFile {
+ fn read(&mut self, _buf: &mut [u8]) -> Result<usize> {
+ Ok(0)
+ }
+ }
+
+ #[test]
+ fn buf_reader_file() {
+ let path: PathBuf = "buf/path".into();
+ let result: BufReader<DummyFile> = File::open(path.clone()).unwrap();
+
+ assert_eq!(DummyFile(path), result.into_inner());
+ }
+
#[test]
fn vist_once() {
let mut fs = VisitOnceFilesystem::<RandomState>::new();
diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs
index 117aeca..ef25659 100644
--- a/tamer/src/ld/poc.rs
+++ b/tamer/src/ld/poc.rs
@@ -133,15 +133,14 @@ fn load_xmlo<'a, 'i, I: Interner<'i>>(
let mut found: FxHashSet<&str> = Default::default();
- let cfile: CanonicalFile<fs::File> = match fs.open(path_str)? {
+ let cfile: CanonicalFile<BufReader<fs::File>> = match fs.open(path_str)? {
VisitOnceFile::FirstVisit(file) => file,
VisitOnceFile::Visited => return Ok(None),
};
let (path, file) = cfile.into();
- let reader = BufReader::new(file);
- let mut xmlo: XmloReader<'_, _, _> = (reader, interner).into();
+ let mut xmlo: XmloReader<'_, _, _> = (file, interner).into();
let mut elig = None;
let mut name: Option<&'i Symbol<'i>> = None;