#unix #traits #permissions #platform #trivial #exposed #function

unix_permissions_ext

A trivial trait bringing missing functions that are not exposed by PermissionsExt to Permissions on UNIX platforms

3 releases

0.1.2 Oct 8, 2022
0.1.1 Oct 7, 2022
0.1.0 Oct 7, 2022

#1124 in Filesystem

Download history 302/week @ 2024-11-17 178/week @ 2024-11-24 297/week @ 2024-12-01 200/week @ 2024-12-08 483/week @ 2024-12-15 565/week @ 2024-12-22 541/week @ 2024-12-29 985/week @ 2025-01-05 1065/week @ 2025-01-12 895/week @ 2025-01-19 629/week @ 2025-01-26 752/week @ 2025-02-02 757/week @ 2025-02-09 1066/week @ 2025-02-16 833/week @ 2025-02-23 838/week @ 2025-03-02

3,620 downloads per month

GPL-2.0-only

14KB
281 lines

UNIXPermissionsExt

BUILD crates.io docs.rs

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 {
    ...
}

Usage

  1. Add it to your dependency:

    $ cd $YOUR_PROJECT
    $ cargo add unix_permissions_ext
    
  2. 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());
    
  3. To use these functions directly with the mode_t type, consider importing raw_fn module:

    use unix_permissions_ext::raw_fn::*;
    

Contributing

Contributions of all forms are welcome, feel free to file an issue or make a pull request!

Test before your commit

  1. Pass the tests

    $ cargo test
    
  2. Format your code

    $ cargo fmt
    

No runtime deps