Enum bit_roles::RoleValue

source ·
pub enum RoleValue<T>
where T: RoleVariant,
{ Role(T), Raw(usize), }
Expand description

The enum holding value of a role.

Variants§

§

Role(T)

Variant that can accept role enum variants.

§

Raw(usize)

Variant that can accept literal integer values.

Implementations§

source§

impl<T> RoleValue<T>
where T: RoleVariant,

source

pub fn from_role(role: T) -> Self

Creates a new RoleValue instance from a role without performing the validation.

§Examples
use bit_roles::{
    BitRole,
    RoleValue,
};

#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
    None = 0,
    Staff = 1,
}

let value = RoleValue::from_role(MyRole::Staff);

assert_eq!(value, RoleValue::Role(MyRole::Staff));
  • role - The role variant.
source

pub fn try_from_role(role: T) -> Result<Self, RoleError>

Validates a role and creates a new RoleValue instance from a it.

§Examples
use bit_roles::{
    BitRole,
    RoleValue,
};

#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
    None = 0,
    Staff = 1,
}

let value = RoleValue::try_from_role(MyRole::Staff).expect("invalid role");

assert_eq!(value, RoleValue::Role(MyRole::Staff));
  • role - The role variant.
source

pub fn from_usize(value: usize) -> Self

Creates a new RoleValue instance from an integer value without performing the validation.

§Examples
use bit_roles::{
    BitRole,
    RoleValue,
};

#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
    None = 0,
    Staff = 1,
}

let value: RoleValue<MyRole> = RoleValue::from_usize(4);

assert_eq!(value, RoleValue::Raw(4));
  • value - The magnitude.
source

pub fn try_from_usize(value: usize) -> Result<Self, RoleError>

Validates an integer value and creates a new RoleValue instance from it.

§Examples
use bit_roles::{
    BitRole,
    RoleValue,
};

#[derive(Debug, BitRole, Copy, Clone)]
enum MyRole {
    None = 0,
    Staff = 1,
}

let value: RoleValue<MyRole> = RoleValue::try_from_usize(4).expect("invalid value");

assert_eq!(value, RoleValue::Raw(4));
  • value - The magnitude.

Trait Implementations§

source§

impl<T> Clone for RoleValue<T>
where T: RoleVariant + Clone,

source§

fn clone(&self) -> RoleValue<T>

Returns a copy 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<T> Debug for RoleValue<T>
where T: RoleVariant + Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<T> From<RoleValue<T>> for usize
where T: RoleVariant,

source§

fn from(val: RoleValue<T>) -> Self

Converts to this type from the input type.
source§

impl<T> PartialEq for RoleValue<T>
where T: RoleVariant,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Copy for RoleValue<T>
where T: RoleVariant + Copy,

source§

impl<T> Eq for RoleValue<T>
where T: RoleVariant,

Auto Trait Implementations§

§

impl<T> Freeze for RoleValue<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for RoleValue<T>
where T: RefUnwindSafe,

§

impl<T> Send for RoleValue<T>
where T: Send,

§

impl<T> Sync for RoleValue<T>
where T: Sync,

§

impl<T> Unpin for RoleValue<T>
where T: Unpin,

§

impl<T> UnwindSafe for RoleValue<T>
where T: UnwindSafe,

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> 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,

§

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>,

§

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>,

§

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.