update readme

master
Avril 4 years ago
parent a1dfcce8f1
commit 23aa13afa5
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -2,7 +2,7 @@
name = "readable-perms" name = "readable-perms"
description = "More usable UNIX file permissions interface" description = "More usable UNIX file permissions interface"
keywords = ["unix", "fs", "permissions", "file", "chmod"] keywords = ["unix", "fs", "permissions", "file", "chmod"]
version = "0.1.2" version = "0.1.3"
authors = ["Avril <flanchan@cumallover.me>"] authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018" edition = "2018"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"

@ -66,6 +66,23 @@ fn do_thing(file: &mut std::fs::File)
} }
``` ```
### Modifying permissions
With default feature `chmod` enabled, also define extension traits for modifying permissions on types that implement `AsRawFd` (like `std::fs::File`), and `AsRef<Path>`.
``` rust
use readable_perms::{FChmodExt,ChmodExt};
fn mod_path<P: AsRef<Path>>(path: P)
{
path.chmod(Permissions::from_mask(0o644)).expect("Uh oh")
}
fn mod_file(file: &mut std::fs::File)
{
file.chmod(Permissinos::from_mask(0u777)).expect("Uh oh")
}
```
## Performance ## Performance
On nightly, most functions are `const fn` incuring no runtime cost for constant definitions. On stable, not so. Either way, we define a global `const` lookup table, so that conversions are as fast as a memory lookup. On nightly, most functions are `const fn` incuring no runtime cost for constant definitions. On stable, not so. Either way, we define a global `const` lookup table, so that conversions are as fast as a memory lookup.

Loading…
Cancel
Save