Struct Role

Source
pub struct Role { /* private fields */ }
Expand description

A role represents a collection of permissions that can be assigned to subjects.

Implementations§

Source§

impl Role

Source

pub fn new(name: impl Into<String>) -> Self

Create a new role with the given name.

Source

pub fn with_id(id: impl Into<String>, name: impl Into<String>) -> Self

Create a new role with a specific ID.

Source

pub fn id(&self) -> &str

Get the role’s unique identifier.

Source

pub fn name(&self) -> &str

Get the role’s name.

Source

pub fn with_description(self, description: impl Into<String>) -> Self

Set the role’s description.

Source

pub fn description(&self) -> Option<&str>

Get the role’s description.

Source

pub fn add_permission(self, permission: Permission) -> Self

Add a permission to this role.

Source

pub fn add_permissions( self, permissions: impl IntoIterator<Item = Permission>, ) -> Self

Add multiple permissions to this role.

Source

pub fn remove_permission(&mut self, permission: &Permission)

Remove a permission from this role.

Source

pub fn has_permission_exact(&self, permission: &Permission) -> bool

Check if this role has a specific permission.

Source

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.

Source

pub fn permissions(&self) -> &PermissionSet

Get all permissions granted by this role.

Source

pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Set metadata for this role.

Source

pub fn metadata(&self, key: &str) -> Option<&str>

Get metadata value for a key.

Source

pub fn all_metadata(&self) -> &HashMap<String, String>

Get all metadata.

Source

pub fn set_active(&mut self, active: bool)

Set whether this role is active.

Source

pub fn is_active(&self) -> bool

Check if this role is active.

Source

pub fn deactivate(self) -> Self

Deactivate this role.

Source

pub fn merge_permissions(&mut self, other: &Role)

Merge permissions from another role into this one.

Trait Implementations§

Source§

impl Clone for Role

Source§

fn clone(&self) -> Role

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Role

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.