pub struct Role { /* private fields */ }Expand description
A role represents a collection of permissions that can be assigned to subjects.
Implementations§
Source§impl Role
impl Role
Sourcepub fn with_id(id: impl Into<String>, name: impl Into<String>) -> Self
pub fn with_id(id: impl Into<String>, name: impl Into<String>) -> Self
Create a new role with a specific ID.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Set the role’s description.
Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
Get the role’s description.
Sourcepub fn add_permission(self, permission: Permission) -> Self
pub fn add_permission(self, permission: Permission) -> Self
Add a permission to this role.
Sourcepub fn add_permissions(
self,
permissions: impl IntoIterator<Item = Permission>,
) -> Self
pub fn add_permissions( self, permissions: impl IntoIterator<Item = Permission>, ) -> Self
Add multiple permissions to this role.
Sourcepub fn remove_permission(&mut self, permission: &Permission)
pub fn remove_permission(&mut self, permission: &Permission)
Remove a permission from this role.
Sourcepub fn has_permission_exact(&self, permission: &Permission) -> bool
pub fn has_permission_exact(&self, permission: &Permission) -> bool
Check if this role has a specific permission.
Sourcepub fn has_permission(
&self,
action: &str,
resource_type: &str,
context: &HashMap<String, String>,
) -> bool
pub fn has_permission( &self, action: &str, resource_type: &str, context: &HashMap<String, String>, ) -> bool
Check if this role grants permission for an action on a resource type.
Sourcepub fn permissions(&self) -> &PermissionSet
pub fn permissions(&self) -> &PermissionSet
Get all permissions granted by this role.
Sourcepub fn with_metadata(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Set metadata for this role.
Sourcepub fn all_metadata(&self) -> &HashMap<String, String>
pub fn all_metadata(&self) -> &HashMap<String, String>
Get all metadata.
Sourcepub fn set_active(&mut self, active: bool)
pub fn set_active(&mut self, active: bool)
Set whether this role is active.
Sourcepub fn deactivate(self) -> Self
pub fn deactivate(self) -> Self
Deactivate this role.
Sourcepub fn merge_permissions(&mut self, other: &Role)
pub fn merge_permissions(&mut self, other: &Role)
Merge permissions from another role into this one.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Role
impl !RefUnwindSafe for Role
impl Send for Role
impl Sync for Role
impl Unpin for Role
impl !UnwindSafe for Role
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