Skip to content

Latest commit

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

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};constRO_THIS:&str = "RoThis";constRW_THIS:&str = "RwThis";constACCESS_THAT:&str = "AccessThat";structUser{name:String,};// A naive implementation of a the Permeable-Trait.implPermeableforUser{fnhas_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)),}}}fnmain(){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);}

About

A permission-demand trait. Decouples the permission-demander from the permission / access provider.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages