10 releases (1 stable)

✓ Uses Rust 2018 edition

1.0.0 May 20, 2020
0.1.8 Nov 18, 2019
0.1.6 Jul 5, 2019

#15 in Unix APIs

Download history 1248/week @ 2020-02-06 1177/week @ 2020-02-13 524/week @ 2020-02-20 786/week @ 2020-02-27 933/week @ 2020-03-05 840/week @ 2020-03-12 660/week @ 2020-03-19 691/week @ 2020-03-26 754/week @ 2020-04-02 829/week @ 2020-04-09 1002/week @ 2020-04-16 1190/week @ 2020-04-23 923/week @ 2020-04-30 1295/week @ 2020-05-07 2165/week @ 2020-05-14 1293/week @ 2020-05-21

4,108 downloads per month
Used in 4 crates (3 directly)

MIT license

10KB
172 lines

MIT Latest Version docs Chat on Miaou

umask

A light utility helping with unix mode representation, with strong types to avoid misusing constants.

The Mode struct implements Display and prints as "rwxrwxrwx"

Import

In Cargo.toml:

umask = "0.1"

Usage

use umask::*;

// You can build from a number:
assert_eq!("rw-r--r--", Mode::from(0b110100100).to_string());
assert_eq!("rw-r--r--", Mode::from(0o644).to_string());

// 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;
assert_eq!("rw----r--", muo.to_string());

// You can build with semantic constructs:
let m = Mode::all()
.without(ALL_EXEC);
assert_eq!("rw-rw-rw-", m.to_string());
let mut m = Mode::new()
.with_class_perm(ALL, READ)
.with_class_perm(USER, WRITE);
assert_eq!("rw-r--r--", m.to_string());

// Or if you like
m |= ALL_EXEC;
assert_eq!("rwxr-xr-x", m.to_string());
let m = ALL_READ | USER_WRITE;
assert_eq!("rw-r--r--", m.to_string());

// you may test a bit or bitset
assert_eq!(m.has(OTHERS_EXEC), false);

No runtime deps