Skip to content

Commit 8864e29

Browse files
authored
Merge pull request #48 from epage/dup
refactor: Reduce reuse
2 parents e00b74b + e67f66a commit 8864e29

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/path/fc.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,18 @@ use std::fmt;
1010
use std::fs;
1111
use std::io::{self, Read};
1212
use std::path;
13-
use std::str;
1413

1514
use Predicate;
1615

1716
#[derive(Clone, Debug, PartialEq)]
18-
pub struct FileContent(Vec<u8>);
17+
struct FileContent(Vec<u8>);
1918

2019
impl FileContent {
2120
pub fn new(path: &path::Path) -> io::Result<FileContent> {
2221
let mut buffer = Vec::new();
2322
fs::File::open(path)?.read_to_end(&mut buffer)?;
2423
Ok(FileContent(buffer))
2524
}
26-
27-
pub fn utf8(&self) -> Result<&str, str::Utf8Error> {
28-
str::from_utf8(&self.0)
29-
}
3025
}
3126

3227
/// Predicate adaper that converts a `path` to file content predicate to byte predicate.

src/path/fs.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,27 @@
77
// except according to those terms.
88

99
use std::fmt;
10-
use std::io;
10+
use std::fs;
11+
use std::io::{self, Read};
1112
use std::path;
13+
use std::str;
1214

1315
use Predicate;
14-
use path::fc::FileContent;
16+
17+
#[derive(Clone, Debug, PartialEq)]
18+
struct FileContent(Vec<u8>);
19+
20+
impl FileContent {
21+
pub fn new(path: &path::Path) -> io::Result<FileContent> {
22+
let mut buffer = Vec::new();
23+
fs::File::open(path)?.read_to_end(&mut buffer)?;
24+
Ok(FileContent(buffer))
25+
}
26+
27+
pub fn utf8(&self) -> Result<&str, str::Utf8Error> {
28+
str::from_utf8(&self.0)
29+
}
30+
}
1531

1632
/// Predicate that compares file matches
1733
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)