permeable 0.3.2

A permission-demand trait. Decouples the permission-demander from the permission / auth provider.
Documentation
  • Coverage
  • 58.33%
    7 out of 12 items documented1 out of 4 items with examples
  • Size
  • Source code size: 21.54 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.82 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • NORICS-net/permeable
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • migmedia

Permeable

Permeable is a permission-demand trait. It helps to decouple the permission-demander from the permission / auth provider.

Our goal was the simplest possible trait to ask for permission. Can be implemented by a permission-provider distinguishing between users.

Example

use permeable::{Permeable, PermissionError};

const RO_THIS: &str = "RoThis";
const RW_THIS: &str = "RwThis";
const ACCESS_THAT: &str = "AccessThat";

struct User {
    name: String,
};

// A naive implementation of a the Permeable-Trait.
impl Permeable for User {
    fn has_perm(&self, permission: &str) -> Result<(), PermissionError> {
        match (self.name.as_str(), permission) {
            ("admin", _) => Ok(()),
            ("peter", ACCESS_THAT) => Ok(()),
            ("peter", RO_THIS) => Ok(()),
            ("paul", RO_THIS) => Ok(()),
            ("paul", RW_THIS) => Ok(()),
            // catch all
            (_, perm) => Err(PermissionError::denied(permission, &self.name)),
        }
    }
}

fn main() {
    let admin = User { name: String::from("admin") };
    assert_eq!(admin.has_perm(RW_THIS), Ok(()));
    let peter = User { name: String::from("peter") };
    assert_eq!(peter.has_perm(ACCESS_THAT), Ok(()));
    assert_eq!(peter.has_perm(RW_THIS).is_err(), true);
}