A light utility helping with unix mode representation, with strong types to avoid misusing constants.
The Mode struct implements Display
and prints as "rwxrwxrwx"
In Cargo.toml:
umask = "0.1"
``` use umask::*;
// You can build from a number: asserteq!("rw-r--r--", Mode::from(0b110100100).tostring()); asserteq!("rw-r--r--", Mode::from(0o644).tostring());
// or from a path: let mode = Mode::try_from(&path)?;
// You may use |
to combine class permissions:
let mu = Mode::from(0o600);
let mo = Mode::from(0o004);
let muo = mu | mo;
asserteq!("rw----r--", muo.tostring());
// You can build with semantic constructs: let m = Mode::all() .without(ALLEXEC); asserteq!("rw-rw-rw-", m.tostring()); let mut m = Mode::new() .withclassperm(ALL, READ) .withclassperm(USER, WRITE); asserteq!("rw-r--r--", m.to_string());
// Or if you like m |= ALLEXEC; asserteq!("rwxr-xr-x", m.tostring()); let m = ALLREAD | USERWRITE; asserteq!("rw-r--r--", m.to_string());
```