Crates.io | unix_permissions_ext |
lib.rs | unix_permissions_ext |
version | 0.1.2 |
source | src |
created_at | 2022-10-07 08:11:01.81948 |
updated_at | 2022-10-08 10:31:51.884486 |
description | A trivial trait bringing missing functions that are not exposed by PermissionsExt to Permissions on UNIX platforms. |
homepage | |
repository | https://github.com/SteveLauC/UNIXPermissionsExt |
max_upload_size | |
id | 682725 |
size | 32,339 |
A trivial trait bringing missing functions that are not exposed by
std::os::unix::fs::PermissionsExt
to std::fs::Permissions
on UNIX platforms.
pub trait UNIXPermissionsExt {
fn set_uid(&self) -> bool;
fn set_gid(&self) -> bool;
fn sticky_bit(&self) -> bool;
fn readable_by_owner(&self) -> bool;
fn writable_by_owner(&self) -> bool;
fn executable_by_owner(&self) -> bool;
fn readable_by_group(&self) -> bool;
fn writable_by_group(&self) -> bool;
fn executable_by_group(&self) -> bool;
fn readable_by_other(&self) -> bool;
fn writable_by_other(&self) -> bool;
fn executable_by_other(&self) -> bool;
fn stringify(&self) -> String;
}
impl UNIXPermissionsExt for Permissions {
...
}
Add it to your dependency:
$ cd $YOUR_PROJECT
$ cargo add unix_permissions_ext
Import this trait and use it just like you are using the standard library!
use std::fs::metadata;
use unix_permissions_ext::UNIXPermissionsExt;
let metadata = metadata("/usr/bin/passwd").expect("can not fetch metadata");
let permission = metadata.permissions();
assert!(permission.set_uid());
println!("Permission: {}", permission.stringify());
To use these functions directly with the mode_t
type, consider importing raw_fn
module:
use unix_permissions_ext::raw_fn::*;
Contributions of all forms are welcome, feel free to file an issue or make a pull request!
Pass the tests
$ cargo test
Format your code
$ cargo fmt