fn filter(mounts: Vec<Mount>, args: &Args) -> DiskResult<Vec<MountStat>> {
    let mut devices = HashSet::new();
    let include_regex = maybe_regex(&args.pattern)?;
    let exclude_regex = maybe_regex(&args.exclude_pattern)?;
    let mut error_count = 0;
    let ms = mounts
        .into_iter()
        .filter(|mount| {
            include_regex
                .as_ref()
                .map(|re| re.is_match(&mount.file))
                .unwrap_or(true)
        })
        .filter(|mount| {
            exclude_regex
                .as_ref()
                .map(|re| !re.is_match(&mount.file))
                .unwrap_or(true)
        })
        .filter_map(|mount| {
            let stat = match statvfs(mount.file.as_bytes()) {
                Ok(stat) => stat,
                Err(e) => {
                    error_count += 1;
                    debug!("Error reading statvfs for path {}: {}", mount.file, e);
                    return None;
                }
            };
            if stat.blocks() > 0 && !mount.file.starts_with("/proc") {
                Some(MountStat {
                    mount: mount,
                    stat: stat,
                })
            } else {
                None
            }
        })
        // If the same device is mounted multiple times, we only want one. In
        // To match df we expect these to come in in sorted order and just keep
        // the first one.
        .filter_map(|ms| {
            if ms.mount.spec.starts_with("/dev") {
                if devices.contains(&ms.mount.spec) {
                    None
                } else {
                    devices.insert(ms.mount.spec.clone());
                    Some(ms)
                }
            } else {
                Some(ms)
            }
        })
        .filter(|ms| {
            args.fs_type
                .as_ref()
                .map(|vfstype| ms.mount.vfstype == *vfstype)
                .unwrap_or(true)
        })
        .filter(|ms| {
            args.exclude_type
                .as_ref()
                .map(|vfstype| ms.mount.vfstype != *vfstype)
                .unwrap_or(true)
        })
        .collect::<Vec<_>>();
    if error_count == 0 {
        Ok(ms)
    } else {
        Err(Error::NotAccessible {
            accessible: ms,
            not_accessible: error_count,
        })
    }
}
/// Convert Mounts into MountStats, applying filters from args
///
/// This:
///
/// * calls `statvfs` on every filesystem in `/proc/mounts`
/// * filters out dummy (0-block) and /proc filesystems
/// * Only shows one of any given `/dev/` filesystem's mount points (the
///   shortest, same as df)
/// * Applies the `pattern` and `type` filters
Convert Mounts into MountStats, applying filters from args
This.


Convert Mounts into MountStats applying filters from args This .
fn filter(mounts: Vec<Mount>, args: &Args) -> DiskResult<Vec<MountStat>> {
    let mut devices = HashSet::new();
    let include_regex = maybe_regex(&args.pattern)?;
    let exclude_regex = maybe_regex(&args.exclude_pattern)?;
    let mut error_count = 0;
    let ms = mounts
        .into_iter()
        .filter(|mount| {
            include_regex
                .as_ref()
                .map(|re| re.is_match(&mount.file))
                .unwrap_or(true)
        })
        .filter(|mount| {
            exclude_regex
                .as_ref()
                .map(|re| !re.is_match(&mount.file))
                .unwrap_or(true)
        })
        .filter_map(|mount| {
            let stat = match statvfs(mount.file.as_bytes()) {
                Ok(stat) => stat,
                Err(e) => {
                    error_count += 1;
                    debug!("Error reading statvfs for path {}: {}", mount.file, e);
                    return None;
                }
            };
            if stat.blocks() > 0 && !mount.file.starts_with("/proc") {
                Some(MountStat {
                    mount: mount,
                    stat: stat,
                })
            } else {
                None
            }
        })
        // If the same device is mounted multiple times, we only want one. In
        // To match df we expect these to come in in sorted order and just keep
        // the first one.
        .filter_map(|ms| {
            if ms.mount.spec.starts_with("/dev") {
                if devices.contains(&ms.mount.spec) {
                    None
                } else {
                    devices.insert(ms.mount.spec.clone());
                    Some(ms)
                }
            } else {
                Some(ms)
            }
        })
        .filter(|ms| {
            args.fs_type
                .as_ref()
                .map(|vfstype| ms.mount.vfstype == *vfstype)
                .unwrap_or(true)
        })
        .filter(|ms| {
            args.exclude_type
                .as_ref()
                .map(|vfstype| ms.mount.vfstype != *vfstype)
                .unwrap_or(true)
        })
        .collect::<Vec<_>>();
    if error_count == 0 {
        Ok(ms)
    } else {
        Err(Error::NotAccessible {
            accessible: ms,
            not_accessible: error_count,
        })
    }
}
fn filter ( mounts : Vec < Mount > , args : & Args ) -> DiskResult < Vec < MountStat > > { let mut devices = HashSet :: new ( ) ; let include_regex = maybe_regex ( & args . pattern ) ? ; let exclude_regex = maybe_regex ( & args . exclude_pattern ) ? ; let mut error_count = 0 ; let ms = mounts . into_iter ( ) . filter ( | mount | { include_regex . as_ref ( ) . map ( | re | re . is_match ( & mount . file ) ) . unwrap_or ( true ) } ) . filter ( | mount | { exclude_regex . as_ref ( ) . map ( | re | ! re . is_match ( & mount . file ) ) . unwrap_or ( true ) } ) . filter_map ( | mount | { let stat = match statvfs ( mount . file . as_bytes ( ) ) { Ok ( stat ) => stat , Err ( e ) => { error_count += 1 ; debug ! ( " " mount file e ) ; return None ; } } ; if stat . blocks ( ) > 0 && ! mount . file . starts_with ( " " ) { Some ( MountStat { mount : mount , stat : stat , } ) } else { None } } ) // If the same device is mounted multiple times, we only want one. In // To match df we expect these to come in in sorted order and just keep // the first one. . filter_map ( | ms | { if ms . mount . spec . starts_with ( " " ) { if devices . contains ( & ms . mount . spec ) { None } else { devices . insert ( ms . mount . spec . clone ( ) ) ; Some ( ms ) } } else { Some ( ms ) } } ) . filter ( | ms | { args . fs_type . as_ref ( ) . map ( | vfstype | ms . mount . vfstype == * vfstype ) . unwrap_or ( true ) } ) . filter ( | ms | { args . exclude_type . as_ref ( ) . map ( | vfstype | ms . mount . vfstype != * vfstype ) . unwrap_or ( true ) } ) . collect :: < Vec < _ > > ( ) ; if error_count == 0 { Ok ( ms ) } else { Err ( Error :: NotAccessible { accessible : ms , not_accessible : error_count , } ) } }
Convert Mounts into MountStats, applying filters from args
This:
Convert Mounts into MountStats applying filters from args This :
mounts
Vec<Mount>
args
&Args
mounts
Vec<Mount>
args
&Args