Skip to main content

Options

Struct Options 

Source
pub struct Options { /* private fields */ }
Expand description

Ordered collection of mount options — fstab(5) field 4.

Options are stored in order and parsed from a comma-separated string with support for quoted values containing commas.

§Examples

let opts = Options::parse("rw,noatime,size=10G").unwrap();
assert!(opts.has("rw"));
assert_eq!(opts.get("size"), Some("10G"));
assert_eq!(opts.len(), 3);

Implementations§

Source§

impl Options

Source

pub fn new() -> Self

Create an empty options collection.

Source

pub fn defaults() -> Self

Create options with a single defaults flag.

This matches the convention that “defaults” is the standard placeholder for default mount options in /etc/fstab.

Source

pub fn parse(raw: &str) -> Result<Self, OptionsError>

Parse a comma-separated options string.

Supports quoted values (both single and double quotes) to preserve commas within values (e.g., context="unconfined_u:object_r:user_tmp_t:s0").

§Errors

Returns OptionsError::EmptyOptionName if an option has an empty name.

Source

pub fn is_empty(&self) -> bool

Returns true if the options collection is empty.

Source

pub fn len(&self) -> usize

Number of options in this collection.

Source

pub fn get(&self, name: &str) -> Option<&str>

Get the value of the last occurrence of an option by name.

Returns None if the option is not found or is a flag (no value). Returns Some("") if the option was specified with an empty value (e.g., key=).

§Last-option-wins semantics

Per mount(8), if an option appears multiple times, the last occurrence wins. This method scans from the end of the list.

§Examples
let opts = Options::parse("size=10G,ro").unwrap();
assert_eq!(opts.get("size"), Some("10G"));
assert_eq!(opts.get("ro"), None); // flag option has no value
assert_eq!(opts.get("nonexistent"), None);
Source

pub fn has(&self, name: &str) -> bool

Check whether an option by name is present (as a flag or key=value).

§Examples
let opts = Options::parse("rw,noatime,size=10G").unwrap();
assert!(opts.has("rw"));
assert!(opts.has("noatime"));
assert!(opts.has("size"));
assert!(!opts.has("ro"));
Source

pub fn contains(&self, name: &str) -> bool

Alias for has, for consistency with std::collections::HashSet.

Source

pub fn iter(&self) -> impl Iterator<Item = &OptItem>

Iterate over all option items in order.

Source

pub fn is_readonly(&self) -> bool

Whether the options imply a read-only mount.

Uses last-option-wins semantics: ro returns true, rw or defaults returns false.

Source

pub fn is_noauto(&self) -> bool

Whether the options imply noauto (do not mount automatically at boot).

Uses last-option-wins semantics.

Source

pub fn has_nofail(&self) -> bool

Whether the nofail option is present (do not halt boot on mount failure).

Source

pub fn is_netdev(&self) -> bool

Whether the _netdev option is present (network-backed device).

Source

pub fn mount_permission(&self) -> MountPermission

Determine the mount permission model based on options.

Uses last-option-wins semantics.

Source

pub fn set(&mut self, name: &str, value: Option<&str>) -> &mut Self

Set a mount option, replacing any existing occurrence with the same name.

The option is appended to the end (last-option-wins position).

§Examples
let mut opts = Options::parse("rw,noatime").unwrap();
opts.set("ro", None).set("size", Some("10G"));
assert!(opts.has("ro"));
assert_eq!(opts.get("size"), Some("10G"));
// Original "rw" replaced by "ro" (last-option-wins)
assert!(opts.is_readonly());

Returns &mut Self for chaining.

Source

pub fn remove(&mut self, name: &str) -> &mut Self

Remove all occurrences of a mount option by name.

Returns &mut Self for chaining.

Source

pub fn append(&mut self, item: OptItem) -> &mut Self

Append an option item to the end of the list.

Returns &mut Self for chaining.

Source

pub fn prepend(&mut self, item: OptItem) -> &mut Self

Prepend an option item at the beginning of the list.

Returns &mut Self for chaining.

Source

pub fn vfs_options(&self) -> impl Iterator<Item = &OptItem>

Iterate over VFS-classified options only.

Source

pub fn fs_options(&self) -> impl Iterator<Item = &OptItem>

Iterate over filesystem-specific options only.

Source

pub fn user_options(&self) -> impl Iterator<Item = &OptItem>

Iterate over userspace options only.

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Options

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Options

Source§

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

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

impl Default for Options

Source§

fn default() -> Options

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

impl<'de> Deserialize<'de> for Options

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Options

Source§

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

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

impl FromStr for Options

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parse a comma-separated options string into an Options collection.

Equivalent to Options::parse.

Source§

type Err = OptionsError

The associated error which can be returned from parsing.
Source§

impl Hash for Options

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Options

Source§

fn eq(&self, other: &Options) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Options

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&str> for Options

Try to convert a string into Options.

Equivalent to Options::parse.

Source§

type Error = OptionsError

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

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Options

Source§

impl StructuralPartialEq for Options

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,