Struct cchmod::Perm[][src]

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

Create a new Perm.

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());

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());

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());

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()
);

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()
);

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

Formats the value using the given formatter. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.