pub struct Mode { /* private fields */ }
Implementations§
Source§impl Mode
Represents Permissions for a file.
impl Mode
Represents Permissions for a file.
§Formatting
String representations of Modes include the extra permission bits,
which modify how the executable permissions are displayed if set.
If you don’t want to include this functionality, call without_any_extra()
before converting the Mode into a string.
Sourcepub const fn all() -> Self
pub const fn all() -> Self
Build a mode with all permissions given to everybody.
This does not include ExtraPermission
bits.
Sourcepub fn try_from(path: &Path) -> Result<Self, Error>
pub fn try_from(path: &Path) -> Result<Self, Error>
Return the mode for the given path.
On non unix platforms, return Mode::all()
Examples found in repository?
8fn list_files() -> io::Result<()> {
9 let root = env::current_dir()?;
10 println!("Current dir: {}", root.to_string_lossy());
11 let mut paths: Vec<PathBuf> = root.read_dir()?
12 .filter_map(|e| e.ok())
13 .map(|e| e.path())
14 .collect();
15 paths.sort_unstable();
16 for path in paths {
17 let mode = Mode::try_from(&path)?;
18 let name = path.file_name().unwrap().to_string_lossy();
19 println!("{} {}", mode, name);
20 }
21 Ok(())
22}
Sourcepub fn parse<T: AsRef<str>>(s: T) -> Result<Self, ParseError>
pub fn parse<T: AsRef<str>>(s: T) -> Result<Self, ParseError>
Try to parse a mode from a string.
Sourcepub const fn has(self, other: Self) -> bool
pub const fn has(self, other: Self) -> bool
Indicates whether the passed class/permissions are all present in self
Sourcepub const fn has_extra(self, other: ExtraPermission) -> bool
pub const fn has_extra(self, other: ExtraPermission) -> bool
Indicates whether the passed extra permission is present in self
Sourcepub const fn with_extra(self, perm: ExtraPermission) -> Self
pub const fn with_extra(self, perm: ExtraPermission) -> Self
Return a new mode, with the extra permission set (does nothing if the extra permission is already set for the mode)
Sourcepub const fn without_extra(self, perm: ExtraPermission) -> Self
pub const fn without_extra(self, perm: ExtraPermission) -> Self
Return a new mode, without the extra permission set (does nothing if the extra permission is not set for the mode)
Sourcepub const fn without_any_extra(self) -> Self
pub const fn without_any_extra(self) -> Self
Return a new mode, without any extra permission bits set (does nothing if no extra permissions are set for the mode)
Sourcepub const fn with_class_perm(self, class: Class, perm: Permission) -> Self
pub const fn with_class_perm(self, class: Class, perm: Permission) -> Self
Return a new mode, with the permission added for the class (does nothing if the permission is already given to that class)
Sourcepub const fn without_class_perm(self, class: Class, perm: Permission) -> Self
pub const fn without_class_perm(self, class: Class, perm: Permission) -> Self
return a new mode, with the permission removed for the class (does nothing if the permission is already given to that class)
Trait Implementations§
Source§impl BitAndAssign for Mode
impl BitAndAssign for Mode
Source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
&=
operation. Read moreSource§impl BitOrAssign for Mode
impl BitOrAssign for Mode
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
|=
operation. Read more