lfs_core/
mount.rs

1use crate::*;
2
3/// A mount point
4#[derive(Debug, Clone)]
5pub struct Mount {
6    pub info: MountInfo,
7    pub fs_label: Option<String>,
8    pub disk: Option<Disk>,
9    pub stats: Result<Stats, StatsError>,
10    pub uuid: Option<String>,
11    pub part_uuid: Option<String>,
12}
13
14impl Mount {
15    /// Return inodes information, when available and consistent
16    pub fn inodes(&self) -> Option<&Inodes> {
17        self.stats
18            .as_ref()
19            .ok()
20            .and_then(|stats| stats.inodes.as_ref())
21    }
22    /// Return the stats, if they could be fetched and
23    /// make sense.
24    ///
25    /// Most often, you don't care *why* there are no stats,
26    /// because the error cases are mostly non storage volumes,
27    /// so it's a best practice to no try to analyze the error
28    /// but just use this option returning method.
29    ///
30    /// The most interesting case is when a network volume is
31    /// unreachable, which you can test with is_unreachable().
32    pub fn stats(&self) -> Option<&Stats> {
33        self.stats.as_ref().ok()
34    }
35    /// Tell whether the reason we have no stats is because the
36    /// filesystem is unreachable
37    pub fn is_unreachable(&self) -> bool {
38        matches!(self.stats, Err(StatsError::Unreachable))
39    }
40
41    #[cfg(unix)]
42    pub fn is_remote(&self) -> bool {
43        self.info.is_remote()
44    }
45
46    #[cfg(windows)]
47    pub fn is_remote(&self) -> bool {
48        self.disk.as_ref().is_some_and(|disk| disk.remote)
49    }
50}