Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/tamer/src
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2020-04-06 22:38:44 -0400
committerMike Gerwitz <mike.gerwitz@ryansg.com>2020-04-28 09:06:25 -0400
commit7ed0691c4561b4747bbbe37830961ae057d5aab3 (patch)
treeee19e131290f5b0e3ebe3ceeeae58a107dae0098 /tamer/src
parentfbfb3c4ba2a90df028bd02e268ce286f99c3e16d (diff)
downloadtame-7ed0691c4561b4747bbbe37830961ae057d5aab3.tar.gz
tame-7ed0691c4561b4747bbbe37830961ae057d5aab3.tar.bz2
tame-7ed0691c4561b4747bbbe37830961ae057d5aab3.zip
[DEV-7084] TAMER: fs: impl File for BufReader
This further simplifies the POC linker.
Diffstat (limited to 'tamer/src')
-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;