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
impl Options
Sourcepub fn defaults() -> Self
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.
Sourcepub fn parse(raw: &str) -> Result<Self, OptionsError>
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.
Sourcepub fn get(&self, name: &str) -> Option<&str>
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);Sourcepub fn has(&self, name: &str) -> bool
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"));Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Alias for has, for consistency with std::collections::HashSet.
Sourcepub fn is_readonly(&self) -> bool
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.
Sourcepub fn is_noauto(&self) -> bool
pub fn is_noauto(&self) -> bool
Whether the options imply noauto (do not mount automatically at boot).
Uses last-option-wins semantics.
Sourcepub fn has_nofail(&self) -> bool
pub fn has_nofail(&self) -> bool
Whether the nofail option is present (do not halt boot on mount failure).
Sourcepub fn mount_permission(&self) -> MountPermission
pub fn mount_permission(&self) -> MountPermission
Determine the mount permission model based on options.
Uses last-option-wins semantics.
Sourcepub fn set(&mut self, name: &str, value: Option<&str>) -> &mut Self
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.
Sourcepub fn remove(&mut self, name: &str) -> &mut Self
pub fn remove(&mut self, name: &str) -> &mut Self
Remove all occurrences of a mount option by name.
Returns &mut Self for chaining.
Sourcepub fn append(&mut self, item: OptItem) -> &mut Self
pub fn append(&mut self, item: OptItem) -> &mut Self
Append an option item to the end of the list.
Returns &mut Self for chaining.
Sourcepub fn prepend(&mut self, item: OptItem) -> &mut Self
pub fn prepend(&mut self, item: OptItem) -> &mut Self
Prepend an option item at the beginning of the list.
Returns &mut Self for chaining.
Sourcepub fn vfs_options(&self) -> impl Iterator<Item = &OptItem>
pub fn vfs_options(&self) -> impl Iterator<Item = &OptItem>
Iterate over VFS-classified options only.
Sourcepub fn fs_options(&self) -> impl Iterator<Item = &OptItem>
pub fn fs_options(&self) -> impl Iterator<Item = &OptItem>
Iterate over filesystem-specific options only.
Sourcepub fn user_options(&self) -> impl Iterator<Item = &OptItem>
pub fn user_options(&self) -> impl Iterator<Item = &OptItem>
Iterate over userspace options only.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Options
impl<'de> Deserialize<'de> for Options
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl TryFrom<&str> for Options
Try to convert a string into Options.
impl TryFrom<&str> for Options
Try to convert a string into Options.
Equivalent to Options::parse.