Mount

Struct Mount 

Source
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

Source

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 and fs_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());
}
Source

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§

Source§

impl Clone for Mount

Source§

fn clone(&self) -> Mount

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mount

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Mount

Source§

fn default() -> Mount

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.