Skip to main content

Perm

Struct Perm 

Source
pub struct Perm {
    pub read: bool,
    pub write: bool,
    pub execute: bool,
}
Expand description

File system object permissions.

See perm for predefined constant values.

Fields§

§read: bool

Flag indicating whether read permission is granted.

§write: bool

Flag indicating whether write permission is granted.

§execute: bool

Flag indicating whether execute permission is granted.

Implementations§

Source§

impl Perm

Source

pub const fn new(read: bool, write: bool, execute: bool) -> Self

Create a new Perm.

Source

pub fn as_num(&self) -> String

Get the octal representation the Perm.

§Examples
use cchmod::Perm;

let p1 = Perm::new(true, true, false);
assert_eq!("6", p1.as_num());

let p2 = Perm::new(true, false, true);
assert_eq!("5", p2.as_num());
Source

pub fn as_sym(&self) -> String

Get the symbolic representation, with ungranted permissions omitted, of the Perm.

§Examples
use cchmod::Perm;

let p1 = Perm::new(true, true, false);
assert_eq!("rw", p1.as_sym());

let p2 = Perm::new(true, false, true);
assert_eq!("rx", p2.as_sym());
Source

pub fn as_sym_full(&self) -> String

Get the symbolic representation, with ungranted permissions as ‘-’, of the Perm.

§Examples
use cchmod::Perm;

let p1 = Perm::new(true, true, false);
assert_eq!("rw-", p1.as_sym_full());

let p2 = Perm::new(true, false, true);
assert_eq!("r-x", p2.as_sym_full());
Source

pub fn from_num(num: &str) -> Result<Self, ParseError>

Create a Perm from its octal form, returning ParseError if the input is invalid.

§Examples
use cchmod::{Perm, ParseError};

assert_eq!(Perm::new(true, true, true), Perm::from_num("7").unwrap());
assert_eq!(Perm::new(true, false, false), Perm::from_num("4").unwrap());

assert_eq!(
    ParseError::UnexpectedEoi { pos: 0 },
    Perm::from_num("").unwrap_err()
);
assert_eq!(
    ParseError::UnexpectedChar {
        pos: 0,
        c: '8',
        expected: Some(vec!['0', '1', '2', '3', '4', '5', '6', '7'])
    },
    Perm::from_num("8").unwrap_err()
);
Source

pub fn from_sym_full(sym: &str) -> Result<Self, ParseError>

Create a Perm from its symbolic form, returning ParseError if the input is invalid.

§Examples
use cchmod::{Perm, ParseError};

assert_eq!(Perm::new(true, true, true), Perm::from_sym_full("rwx").unwrap());
assert_eq!(Perm::new(true, false, false), Perm::from_sym_full("r--").unwrap());

assert_eq!(
    ParseError::UnexpectedEoi { pos: 2 },
    Perm::from_sym_full("rw").unwrap_err()
);
assert_eq!(
    ParseError::UnexpectedChar { pos: 3, c: 'r', expected: None },
    Perm::from_sym_full("rwxr").unwrap_err()
);
Source

pub const fn diff(&self, other: &Self) -> PermDiff

Compute the diff (PermDiff) between two Perms.

§Examples
use cchmod::{Perm, PermDiff, DiffOp::*};

let a = Perm::from_num("7").unwrap();
let b = Perm::from_num("6").unwrap();

assert_eq!(
    PermDiff { read: Same, write: Same, execute: Minus },
    a.diff(&b)
);

Trait Implementations§

Source§

impl AsNum for Perm

Source§

fn as_num(&self) -> String

Source§

impl AsSym for Perm

Source§

fn as_sym(&self) -> String

Source§

impl Debug for Perm

Source§

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

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

impl From<(bool, bool, bool)> for Perm

Source§

fn from(tup: (bool, bool, bool)) -> Self

Create a Perm from a tuple of boolean with form (user, group, other).

Source§

impl PartialEq for Perm

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Perm

Auto Trait Implementations§

§

impl Freeze for Perm

§

impl RefUnwindSafe for Perm

§

impl Send for Perm

§

impl Sync for Perm

§

impl Unpin for Perm

§

impl UnsafeUnpin for Perm

§

impl UnwindSafe for Perm

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> 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, 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.