4 ms·
If we make PathRef an alias of AsRef<Path>, the following code looks much prettier to me: pub fn read(path: PathRef) -> io::Result<Vec<u8>> { fn inner(path
by rfoo 4y ago
If we make PathRef an alias of AsRef<Path>, the following code looks much prettier to me:
pub fn read(path: PathRef) -> io::Result<Vec<u8>> {
fn inner(path: &Path) -> io::Result<Vec<u8>> {
let mut file = File::open(path)?;
let mut bytes = Vec::new();
file.read_to_end(&mut bytes)?;
Ok(bytes)
}
inner(path.as_ref())
}
I don't see noise in the remaining code, like the author said, they all have meaningful semantic (besides the repeated return type).