Replace simple match with map_or

This commit is contained in:
bootandy
2018-05-01 14:38:34 +01:00
parent c5830c5d00
commit 39db8b86fd
+5 -9
View File
@@ -9,23 +9,19 @@ fn get_block_size() -> u64 {
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> { pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
match d.metadata().ok() { d.metadata().ok().map_or(None, |md| {
Some(md) => {
let inode = Some((md.ino(), md.dev())); let inode = Some((md.ino(), md.dev()));
if use_apparent_size { if use_apparent_size {
Some((md.len(), inode)) Some((md.len(), inode))
} else { } else {
Some((md.blocks() * get_block_size(), inode)) Some((md.blocks() * get_block_size(), inode))
} }
} })
None => None,
}
} }
#[cfg(not(target_family = "unix"))] #[cfg(not(target_family = "unix"))]
pub fn get_metadata(d: &DirEntry, _apparent: bool) -> Option<(u64, Option<(u64, u64)>)> { pub fn get_metadata(d: &DirEntry, _apparent: bool) -> Option<(u64, Option<(u64, u64)>)> {
match d.metadata().ok() { d.metadata().ok().map_or(None, |md| {
Some(md) => Some((md.len(), None)), Some((md.len(), None))
None => None, })
}
} }