Struct file_mode::Mode [−][src]
Unix file mode.
All file type, special and protection bits described in sys/stat.h
are represented.
The Mode
can represent a file mode partially by the use of a bitmask. Only modified bits will be changed in the target file.
Modifications specific only to directories (see ProtectionBit::Search) are handled correctly.
The Mode
can be displayed as a string according to the POSIX standard for the ls
command.
Mode bits can be set with chmod
compatible string.
Implementations
impl Mode
[src]
pub fn new(mode: u32, mask: u32) -> Mode
[src]
Constructs Mode from mode value and mask representing which special and permissions bits will be applied to the target file mode.
pub fn empty() -> Mode
[src]
Constructs Mode with no bits sets and empty mask.
pub fn from_path(path: impl AsRef<Path>) -> Result<Mode, Error>
[src]
Constructs Mode from mode value of the file represented by the path.
The mask will be set to 0o7777
meaning that all the special and permissions bits will be applied
to the target file mode.
pub fn from_path_nofollow(path: impl AsRef<Path>) -> Result<Mode, Error>
[src]
Like Mode::from_path but will not follow symbolic links.
pub fn from_file(file: &File) -> Result<Mode, Error>
[src]
Constructs Mode from mode value of the file.
The mask will be set to 0o7777
meaning that all the special and permissions bits will be applied
to the target file mode.
pub fn mode(&self) -> u32
[src]
Gets mode value.
pub fn mode_mask(&self) -> (u32, u32)
[src]
Gets mode value and mask that represents bits of the mode that would be applied to the target file mode.
If the mode represents a directory the search bit will be handled accordingly.
pub fn file_type(&self) -> Option<FileType>
[src]
Gets FileType if corresponding bit patterns are present and valid in the mode value.
pub fn user_protection(&self, user: User) -> Protection
[src]
Gets Protection bits for User.
pub fn user_special(&self, user: User) -> Special
[src]
- For User::Owner the SpecialBit::SetId bit will represent the
set-user-ID
mode bit. - For User::Group the SpecialBit::SetId bit will represent the
set-group-ID
mode bit.
pub fn add(&mut self, mode: &Mode)
[src]
Sets bits that are set in the given mode according to mask.
pub fn sub(&mut self, mode: &Mode)
[src]
Clears bits that are set in the given mode according to mask.
pub fn set(&mut self, mode: &Mode)
[src]
Sets values of bits that are set or clear in the given mode according to mask.
pub fn forget(&mut self, mode: &Mode)
[src]
Forgets values of bits that are set or clear in the given mode by clearing bits in the mask.
pub fn with_file_type(self, file_type: FileType) -> Mode
[src]
Returns self with given bit pattern representing FileType set.
pub fn with_protection(self, user: User, protection: &Protection) -> Mode
[src]
Returns self with bit pattern and mask for Protection bits set for User.
pub fn with_special(self, user: User, special: &Special) -> Mode
[src]
Returns self with bit pattern and mask for Special bits set for User.
- For User::Owner the SpecialBit::SetId bit will represent the
set-user-ID
mode bit. - For User::Group the SpecialBit::SetId bit will represent the
set-group-ID
mode bit.
pub fn set_file_type(&mut self, file_type: FileType)
[src]
Sets bit pattern representing given FileType.
pub fn set_protection(&mut self, user: User, protection: &Protection)
[src]
Sets bit pattern and mask for Protection bits for User.
pub fn set_special(&mut self, user: User, special: &Special)
[src]
Sets bit pattern and mask for Special bits for User.
- For User::Owner the SpecialBit::SetId bit will represent the
set-user-ID
mode bit. - For User::Group the SpecialBit::SetId bit will represent the
set-group-ID
mode bit.
pub fn set_str(&mut self, mode_str: &str) -> Result<(), ModeParseError>
[src]
Sets bits according to the mode string (as described in Linux chmod
manual).
Only bits described by the string will be represented in the mask.
Note: Current value of mode is used as a reference for operations that use the
user as the source of bits (like g+u
). Consider constructing Mode
using Mode::from_file or Mode::from_path before using this method.
pub fn set_str_umask(
&mut self,
mode_str: &str,
umask: u32
) -> Result<(), ModeParseError>
[src]
&mut self,
mode_str: &str,
umask: u32
) -> Result<(), ModeParseError>
Like Mode::set_str but allows to specify umask value to use instead of the calling process’s umask.
pub fn apply_umask(&mut self, umask: u32)
[src]
Clears protection bits set in the umask value if they were set.
pub fn apply_to(&self, mode: u32) -> u32
[src]
Applies mode changes to given mode value.
Only bits set in the mask are modified.
Returns the resulting mode value.
If the mode value passed as an argument represents a directory the search bit will be handled accordingly.
pub fn apply_to_path(&self, path: impl AsRef<Path>) -> Result<u32, Error>
[src]
Applies mode changes to the mode of a file represented by the path.
Only bits set in the mask are modified.
Returns the resulting mode value.
If the mode value of the file passed as an argument represents a directory the search bit will be handled accordingly.
The file’s mode is not modified.
pub fn apply_to_path_nofollow(
&self,
path: impl AsRef<Path>
) -> Result<u32, Error>
[src]
&self,
path: impl AsRef<Path>
) -> Result<u32, Error>
Like Mode::apply_to_path but does not follow symbolic links.
pub fn set_mode_path(&self, path: impl AsRef<Path>) -> Result<u32, Error>
[src]
Sets the mode of the file, represented by the path, by applying the mode changes to its current mode.
Only bits set in the mask are modified.
Returns the new file mode value.
If the mode value of the file passed as an argument represents a directory the search bit will be handled accordingly.
The file’s mode is modified.
pub fn set_mode_path_nofollow(
&self,
path: impl AsRef<Path>
) -> Result<u32, Error>
[src]
&self,
path: impl AsRef<Path>
) -> Result<u32, Error>
Like Mode::set_mode_path but does not follow symbolic links.
pub fn set_mode_file(&self, file: &File) -> Result<u32, Error>
[src]
Sets the mode of the file by applying the mode changes to its current mode.
Only bits set in the mask are modified.
Returns the new file mode value.
If the mode value of the file passed as an argument represents a directory the search bit will be handled accordingly.
The file’s mode is modified.
Trait Implementations
impl Clone for Mode
[src]
impl Debug for Mode
[src]
impl Display for Mode
[src]
impl Eq for Mode
[src]
impl From<u32> for Mode
[src]
impl FromIterator<Mode> for Mode
[src]
fn from_iter<I: IntoIterator<Item = Mode>>(iter: I) -> Self
[src]
impl Hash for Mode
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<Mode> for Mode
[src]
impl StructuralEq for Mode
[src]
impl StructuralPartialEq for Mode
[src]
Auto Trait Implementations
impl RefUnwindSafe for Mode
impl Send for Mode
impl Sync for Mode
impl Unpin for Mode
impl UnwindSafe for Mode
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,