Struct bit_roles::RoleManager
source · pub struct RoleManager<T>(pub usize, pub PhantomData<T>);Expand description
The default role manager with compile-time value checks.
Tuple Fields§
§0: usize§1: PhantomData<T>Implementations§
source§impl<T> RoleManager<T>where
T: RoleVariant,
impl<T> RoleManager<T>where
T: RoleVariant,
sourcepub fn add_one(&mut self, role: T) -> &mut Self
pub fn add_one(&mut self, role: T) -> &mut Self
Adds a single role to the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
let mut roles = MyRole::empty();
// Add a new role to the manager.
roles.add_one(MyRole::Staff);
assert!(roles.has_one(MyRole::Staff));role- The role to add to the manager.
sourcepub fn add_all(&mut self, roles: Vec<T>) -> &mut Self
pub fn add_all(&mut self, roles: Vec<T>) -> &mut Self
Adds multiple roles to the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
let mut roles = MyRole::empty();
// Add multiple new roles to the manager.
roles.add_all(vec![MyRole::Staff, MyRole::Member]);
assert!(roles.has_all(vec![MyRole::Staff, MyRole::Member]));roles- The roles to add to the manager.
sourcepub fn remove_one(&mut self, role: T) -> &mut Self
pub fn remove_one(&mut self, role: T) -> &mut Self
Removes a single role from the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
let mut roles = MyRole::empty();
// Remove a role from the manager.
roles.remove_one(MyRole::Staff);
assert!(roles.not_one(MyRole::Staff));role- The role to remove from the manager.
sourcepub fn remove_all(&mut self, roles: Vec<T>) -> &mut Self
pub fn remove_all(&mut self, roles: Vec<T>) -> &mut Self
Removes multiple roles from the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
let mut roles = MyRole::empty();
// Remove multiple roles from the manager.
roles.remove_all(vec![MyRole::Staff, MyRole::Member]);
assert!(roles.not_all(vec![MyRole::Staff, MyRole::Member]));roles- The roles to remove from the manager.
sourcepub fn has_one(&self, role: T) -> bool
pub fn has_one(&self, role: T) -> bool
Checks whether a single role is assigned to the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
// Create a role manager with initial `Staff` role.
let mut roles = MyRole::from_value(MyRole::Staff.into());
// Check if the manager has a single role.
let has_role = roles.has_one(MyRole::Staff);
assert!(has_role);role- The role to check against the manager.
sourcepub fn has_all(&self, roles: Vec<T>) -> bool
pub fn has_all(&self, roles: Vec<T>) -> bool
Checks whether each of the roles is assigned to the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
let mut roles = MyRole::empty();
// Add multiple roles to the role manager.
roles.add_all(vec![MyRole::Staff, MyRole::Member]);
// Check if the manager has all the provided roles.
let has_roles = roles.has_all(vec![MyRole::Staff, MyRole::Member]);
assert!(has_roles);roles- The roles to check against the manager.
sourcepub fn has_any(&self, roles: Vec<T>) -> bool
pub fn has_any(&self, roles: Vec<T>) -> bool
Checks whether any one of the roles is assigned to the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
let mut roles = MyRole::empty();
// Create a role manager with initial `Staff` role.
let mut roles = MyRole::from_value(MyRole::Staff.into());
// Check if the manager has any of the provided roles.
let has_roles = roles.has_any(vec![MyRole::Staff, MyRole::Member]);
assert!(has_roles);roles- The roles to check against the manager.
sourcepub fn not_one(&self, role: T) -> bool
pub fn not_one(&self, role: T) -> bool
Checks whether a single role is not assigned to the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
let mut roles = MyRole::empty();
// Check if the manager does not have a single role.
let does_not_have_role = roles.not_one(MyRole::Staff);
assert!(does_not_have_role);role- The role to check against the manager.
sourcepub fn not_all(&self, roles: Vec<T>) -> bool
pub fn not_all(&self, roles: Vec<T>) -> bool
Checks whether each of the roles is not assigned to the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
let mut roles = MyRole::empty();
// Check if the manager does not have all of the provided roles.
let does_not_have_roles = roles.not_all(vec![MyRole::Staff, MyRole::Member]);
assert!(does_not_have_roles);roles- The roles to check against the manager.
sourcepub fn not_any(&self, roles: Vec<T>) -> bool
pub fn not_any(&self, roles: Vec<T>) -> bool
Checks whether any of the roles is not assigned to the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
let mut roles = MyRole::empty();
// Check if the manager does not have any of the provided roles.
let does_not_have_roles = roles.not_any(vec![MyRole::Staff, MyRole::Member]);
assert!(does_not_have_roles);roles- The roles to check against the manager.
sourcepub fn get_value(&self) -> usize
pub fn get_value(&self) -> usize
Returns the value of the manager instance.
§Examples
use bit_roles::BitRole;
#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
let roles = MyRole::empty();
// Get value of the manager instance.
let value = roles.get_value();
assert_eq!(value, 0);Trait Implementations§
source§impl<T: Debug> Debug for RoleManager<T>
impl<T: Debug> Debug for RoleManager<T>
source§impl<T> PartialEq for RoleManager<T>
impl<T> PartialEq for RoleManager<T>
impl<T> Eq for RoleManager<T>
Auto Trait Implementations§
impl<T> Freeze for RoleManager<T>
impl<T> RefUnwindSafe for RoleManager<T>where
T: RefUnwindSafe,
impl<T> Send for RoleManager<T>where
T: Send,
impl<T> Sync for RoleManager<T>where
T: Sync,
impl<T> Unpin for RoleManager<T>where
T: Unpin,
impl<T> UnwindSafe for RoleManager<T>where
T: UnwindSafe,
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