pub struct RoleBuilder { /* private fields */ }Expand description
Builder for creating roles with a fluent API.
Implementations§
Source§impl RoleBuilder
impl RoleBuilder
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Set the role description.
Sourcepub fn permission(self, permission: Permission) -> Self
pub fn permission(self, permission: Permission) -> Self
Add a permission to the role.
Sourcepub fn permissions(
self,
permissions: impl IntoIterator<Item = Permission>,
) -> Self
pub fn permissions( self, permissions: impl IntoIterator<Item = Permission>, ) -> Self
Add multiple permissions to the role.
Sourcepub fn allow<I, S>(self, resource: impl Into<String>, actions: I) -> Self
pub fn allow<I, S>(self, resource: impl Into<String>, actions: I) -> Self
Add permissions with fluent allow syntax.
§Example
use role_system::role::RoleBuilder;
let role = RoleBuilder::new()
.name("admin")
.allow("users", ["create", "read", "update", "delete"])
.allow("roles", ["read", "assign"])
.build().unwrap();Sourcepub fn deny<I, S>(self, resource: impl Into<String>, actions: I) -> Self
pub fn deny<I, S>(self, resource: impl Into<String>, actions: I) -> Self
Add permissions with deny semantics (creates negative conditions).
§Example
use role_system::role::RoleBuilder;
let role = RoleBuilder::new()
.name("restricted_admin")
.allow("users", ["read", "update"])
.deny("system", ["shutdown"])
.build().unwrap();Sourcepub fn allow_when<I, S, F>(
self,
resource: impl Into<String>,
actions: I,
condition: F,
) -> Self
pub fn allow_when<I, S, F>( self, resource: impl Into<String>, actions: I, condition: F, ) -> Self
Add permissions with conditional access.
§Example
use role_system::role::RoleBuilder;
let role = RoleBuilder::new()
.name("user")
.allow_when("profile", ["update"], |ctx|
ctx.get("user_id") == ctx.get("target_id"))
.build().unwrap();Trait Implementations§
Source§impl Debug for RoleBuilder
impl Debug for RoleBuilder
Source§impl Default for RoleBuilder
impl Default for RoleBuilder
Source§fn default() -> RoleBuilder
fn default() -> RoleBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RoleBuilder
impl !RefUnwindSafe for RoleBuilder
impl Send for RoleBuilder
impl Sync for RoleBuilder
impl Unpin for RoleBuilder
impl !UnwindSafe for RoleBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more