pub struct Mount {
pub device: String,
pub mountpoint: PathBuf,
pub fstype: String,
pub mountopts: String,
}
Expand description
Represent a mountpoint
Fields§
§device: String
The device name (either a path or something like zram0)
mountpoint: PathBuf
The target directory it has been mounted to
fstype: String
Type of filesystem
mountopts: String
Mount options
Implementations§
Source§impl Mount
impl Mount
Sourcepub fn list() -> Result<impl Iterator<Item = Self>, LsblkError>
pub fn list() -> Result<impl Iterator<Item = Self>, LsblkError>
List out all mountpoints and populate all fields.
§Errors
Since this function depends on the existence of /proc/mounts
, failures to open the file
will cause crate::LsblkError::ReadFile
.
§Caveats
If for some reason /proc/mounts
is not formatted properly, the iterator will skip those
lines. This includes
- trailing whitespace
fs_freq
andfs_passno
(which are the last 2 fields on each line) not set to 0- not separating the fields with only 1 single space (
' '
)
For more information, visit proc_pid_mounts(5)
.
§Examples
for m in lsblk::Mount::list()? {
println!("{} mounted at {}", m.device, m.mountpoint.display());
}
Sourcepub fn iter_mountopts(&self) -> impl Iterator<Item = (&str, Option<&str>)>
pub fn iter_mountopts(&self) -> impl Iterator<Item = (&str, Option<&str>)>
List out the mounting options (fs_mntopts
).
This returns an iterator of (key, optional value).
§Examples
let mountopts = String::from("rw,relatime,compress=zstd:1,ssd,discard=async,subvol=/root");
let m = lsblk::Mount {
mountopts,
..lsblk::Mount::default()
};
let mut it = m.iter_mountopts();
assert_eq!(it.next(), Some(("rw", None)));
assert_eq!(it.next(), Some(("relatime", None)));
assert_eq!(it.next(), Some(("compress", Some("zstd:1"))));
assert_eq!(it.next(), Some(("ssd", None)));
assert_eq!(it.next(), Some(("discard", Some("async"))));
assert_eq!(it.next(), Some(("subvol", Some("/root"))));
assert_eq!(it.next(), None);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Mount
impl RefUnwindSafe for Mount
impl Send for Mount
impl Sync for Mount
impl Unpin for Mount
impl UnwindSafe for Mount
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more