Struct bit_roles::RoleManagerUnchecked
source · pub struct RoleManagerUnchecked<T>(pub usize, pub PhantomData<T>);Expand description
The unchecked role manager. Typically used when you need to use raw integer role values or have complex enum definitions.
Tuple Fields§
§0: usize§1: PhantomData<T>Implementations§
source§impl<T> RoleManagerUnchecked<T>where
T: RoleVariant,
impl<T> RoleManagerUnchecked<T>where
T: RoleVariant,
sourcepub fn try_add_one(
&mut self,
role: RoleValue<T>,
) -> Result<&mut Self, RoleError>
pub fn try_add_one( &mut self, role: RoleValue<T>, ) -> Result<&mut Self, RoleError>
Validates and adds a single role value to the manager instance. This is a non-panicking equivalent of the add_one method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
let mut roles = MyRole::empty();
// Add a new role to the manager.
roles
.try_add_one(RoleValue::Role(MyRole::Staff))
.expect("invalid role");
assert!(roles.has_one(MyRole::Staff));role- The role value to add to the manager.
sourcepub fn try_add_all(
&mut self,
roles: Vec<RoleValue<T>>,
) -> Result<&mut Self, RoleError>
pub fn try_add_all( &mut self, roles: Vec<RoleValue<T>>, ) -> Result<&mut Self, RoleError>
Validates and adds multiple role values to the manager instance. This is a non-panicking equivalent of the add_all method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
let mut roles = MyRole::empty();
// Add multiple new roles to the manager.
roles
.try_add_all(vec![
RoleValue::Role(MyRole::Staff),
RoleValue::Role(MyRole::Member),
])
.expect("invalid roles");
assert!(roles.has_all(vec![MyRole::Staff, MyRole::Member]));role- The role values to add to the manager.
sourcepub fn try_remove_one(
&mut self,
role: RoleValue<T>,
) -> Result<&mut Self, RoleError>
pub fn try_remove_one( &mut self, role: RoleValue<T>, ) -> Result<&mut Self, RoleError>
Validates and removes a single role value from the manager instance. This is a non-panicking equivalent of the remove_one method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
let mut roles = MyRole::empty();
// Remove a role from the manager.
roles
.try_remove_one(RoleValue::Role(MyRole::Staff))
.expect("invalid role");
assert!(roles.not_one(MyRole::Staff));role- The role value to remove from the manager.
sourcepub fn try_remove_all(
&mut self,
roles: Vec<RoleValue<T>>,
) -> Result<&mut Self, RoleError>
pub fn try_remove_all( &mut self, roles: Vec<RoleValue<T>>, ) -> Result<&mut Self, RoleError>
Validates and removes multiple role values from the manager instance. This is a non-panicking equivalent of the remove_all method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
let mut roles = MyRole::empty();
// Remove multiple roles from the manager.
roles
.try_remove_all(vec![
RoleValue::Role(MyRole::Staff),
RoleValue::Role(MyRole::Member),
])
.expect("invalid roles");
assert!(roles.not_all(vec![MyRole::Staff, MyRole::Member]));role- The role values to remove from the manager.
sourcepub fn try_has_one(&self, role: RoleValue<T>) -> Result<bool, RoleError>
pub fn try_has_one(&self, role: RoleValue<T>) -> Result<bool, RoleError>
Validates and checks whether a single role is assigned to the manager instance. This is a non-panicking equivalent of the has_one method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
// 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
.try_has_one(RoleValue::Role(MyRole::Staff))
.expect("invalid role");
assert!(has_role);role- The role value to check against the manager.
sourcepub fn try_has_all(&self, roles: Vec<RoleValue<T>>) -> Result<bool, RoleError>
pub fn try_has_all(&self, roles: Vec<RoleValue<T>>) -> Result<bool, RoleError>
Validates and checks whether each of the roles is assigned to the manager instance. This is a non-panicking equivalent of the has_all method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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
.try_has_all(vec![
RoleValue::Role(MyRole::Staff),
RoleValue::Role(MyRole::Member),
])
.expect("invalid roles");
assert!(has_roles);role- The role values to check against the manager.
sourcepub fn try_has_any(&self, roles: Vec<RoleValue<T>>) -> Result<bool, RoleError>
pub fn try_has_any(&self, roles: Vec<RoleValue<T>>) -> Result<bool, RoleError>
Validates and checks whether any one of the roles is assigned to the manager instance. This is a non-panicking equivalent of the has_any method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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
.try_has_any(vec![
RoleValue::Role(MyRole::Staff),
RoleValue::Role(MyRole::Member),
])
.expect("invalid roles");
assert!(has_roles);role- The role values to check against the manager.
sourcepub fn try_not_one(&self, role: RoleValue<T>) -> Result<bool, RoleError>
pub fn try_not_one(&self, role: RoleValue<T>) -> Result<bool, RoleError>
Validates and checks whether a single role is not assigned to the manager instance. This is a non-panicking equivalent of the not_one method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
let mut roles = MyRole::empty();
// Check if the manager does not have a single role.
let does_not_have_role = roles
.try_not_one(RoleValue::Role(MyRole::Staff))
.expect("invalid role");
assert!(does_not_have_role);role- The role value to check against the manager.
sourcepub fn try_not_all(&self, roles: Vec<RoleValue<T>>) -> Result<bool, RoleError>
pub fn try_not_all(&self, roles: Vec<RoleValue<T>>) -> Result<bool, RoleError>
Validates and checks whether each of the roles is not assigned to the manager instance. This is a non-panicking equivalent of the not_all method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
let mut roles = MyRole::empty();
// Check if the manager does not have all of the provided roles.
let does_not_have_roles = roles
.try_not_all(vec![
RoleValue::Role(MyRole::Staff),
RoleValue::Role(MyRole::Member),
])
.expect("invalid roles");
assert!(does_not_have_roles);role- The role values to check against the manager.
sourcepub fn try_not_any(&self, roles: Vec<RoleValue<T>>) -> Result<bool, RoleError>
pub fn try_not_any(&self, roles: Vec<RoleValue<T>>) -> Result<bool, RoleError>
Validates and checks whether any of the roles is not assigned to the manager instance. This is a non-panicking equivalent of the not_any method.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
let mut roles = MyRole::empty();
// Check if the manager does not have any of the provided roles.
let does_not_have_roles = roles
.try_not_any(vec![
RoleValue::Role(MyRole::Staff),
RoleValue::Role(MyRole::Member),
])
.expect("invalid roles");
assert!(does_not_have_roles);role- The role values to check against the manager.
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. Panics if the role is invalid. Use try_add_one as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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. Panics if any of the roles is invalid. Use try_add_all as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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. Panics if the role is invalid. Use try_remove_one as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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. Panics if any of the roles is invalid. Use try_remove_all as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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. Panics if the role is invalid. Use try_has_one as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
// 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. Panics if any of the roles is invalid. Use try_has_all as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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. Panics if any of the roles is invalid. Use try_has_any as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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. Panics if the role is invalid. Use try_not_one as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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. Panics if any of the roles is invalid. Use try_not_all as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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. Panics if any of the roles is invalid. Use try_not_any as a non-panicking equivalent.
§Examples
use bit_roles::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
Member = 2,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
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::{
BitRoleUnchecked,
RoleValue,
};
#[derive(Debug, BitRoleUnchecked, Copy, Clone)]
enum MyRole {
None = 0,
Staff = 1,
}
impl Into<usize> for MyRole {
fn into(self) -> usize {
self as usize
}
}
let roles = MyRole::empty();
// Get value of the manager instance.
let value = roles.get_value();
assert_eq!(value, 0);