du: refactor to use ? shortcut
@@ -55,9 +55,8 @@ struct Stat {
impl Stat {
fn new(path: PathBuf) -> Result<Stat> {
- match fs::symlink_metadata(&path) {
- Ok(metadata) => {
- return Ok(Stat {
+ let metadata = fs::symlink_metadata(&path)?;
+ Ok(Stat {
path: path,
is_dir: metadata.is_dir(),
size: metadata.len(),
@@ -68,9 +67,6 @@ impl Stat {
modified: metadata.mtime() as u64,
})
}
- Err(e) => Err(e),
- }
- }
}
// this takes `my_stat` to avoid having to stat files multiple times.
