Skip to main content

EnumMap

Struct EnumMap 

Source
pub struct EnumMap<Ids: MapEnum, T>(/* private fields */);
Expand description

Array which using enum as index

Implementations§

Source§

impl<Ids: MapEnum, T> EnumMap<Ids, T>

Source

pub const fn from_array(data: <Ids::Array as Array>::Map<T>) -> Self

Create map from array, recomand using map_new or map_enum!(if require const or move value) instead

Source

pub const fn as_array(&self) -> &<Ids::Array as Array>::Map<T>

Returns a shared reference to the underlying array.

Source

pub const fn as_array_mut(&mut self) -> &mut <Ids::Array as Array>::Map<T>

Returns a mutable reference to the underlying array.

Source

pub const fn into_array(self) -> <Ids::Array as Array>::Map<T>

Consumes the enum map and returns the underlying array.

Source

pub const fn remap<TIds: MapEnum<Array = Ids::Array>>( &self, ) -> &EnumMap<TIds, T>

Reinterprets the enum map as being indexed by a different enum type that shares the same underlying array.

Source

pub const fn remap_mut<TIds: MapEnum<Array = Ids::Array>>( &mut self, ) -> &mut EnumMap<TIds, T>

Mutable version of remap.

Source

pub fn map_new(map: impl FnMut(Ids::Discriminant) -> T) -> Self

Create map by mapping closure, map will call excctally once for each enum variant, using map_enum! instead if require const or move value

Source

pub const fn map_as_ref<'a>(&'a self) -> EnumMap<Ids, &'a T>

Creates a new enum map where each element references the corresponding element in self.

Source

pub const fn map_as_mut<'a>(&'a mut self) -> EnumMap<Ids, &'a mut T>

Creates a new enum map where each element mutably references the corresponding element in self.

Source

pub const fn transparent_wrap<U: TransparentWrapper<T>>(self) -> EnumMap<Ids, U>

Wraps each element of the map in a TransparentWrapper, safe because the repr is identical.

Source

pub const fn transparent_peel<U>(self) -> EnumMap<Ids, U>
where T: TransparentWrapper<U>,

Unwraps (peels) each element from a TransparentWrapper, safe because the repr is identical.

Source§

impl<Ids: MapEnum + PlainMapEnum, T> EnumMap<Ids, T>

Source

pub const fn cget(&self, index: &Ids) -> &T

Gets a reference to the element at the index given by the enum variant index. This is a const-compatible version of the Index trait.

Source

pub const fn cget_mut(&mut self, index: &Ids) -> &mut T

Gets a mutable reference to the element at the index given by the enum variant index. This is a const-compatible version of the IndexMut trait.

Source§

impl<Ids0: MapEnum<Discriminant: Clone>, Ids1: MapEnum, T> EnumMap<Ids0, EnumMap<Ids1, T>>

Source

pub fn map_new2( map: impl FnMut(Ids0::Discriminant, Ids1::Discriminant) -> T, ) -> Self

Creates a 2-level enum map by invoking the closure for every combination of (Ids0, Ids1) variants.

Trait Implementations§

Source§

impl<Ids: MapEnum, T> AsMut<<<Ids as MapEnum>::Array as Array>::Map<T>> for EnumMap<Ids, T>

Source§

fn as_mut(&mut self) -> &mut <Ids::Array as Array>::Map<T>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<Ids: MapEnum, T> AsRef<<<Ids as MapEnum>::Array as Array>::Map<T>> for EnumMap<Ids, T>

Source§

fn as_ref(&self) -> &<Ids::Array as Array>::Map<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<Ids: MapEnum<Array: Array<Map<Fld>: Copy>>, Fld: BitsCast> BitsCast for EnumMap<Ids, Fld>

Source§

const BITS: u32

Source§

fn from_underlying<Bits: PrimaryInt>(v: Bits) -> Self

Convert from underlying int, data is store at lowest Self::BITS, higher bits can be any value
Source§

fn into_underlying<Bits: PrimaryInt>(sf: Self) -> Bits

Convert into underlying int, data must store at lowest Self::BITS, higher bits can be any value
Source§

impl<Ids: MapEnum<Array: Array<Map<T>: Clone>>, T> Clone for EnumMap<Ids, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Ids: MapEnum<Array: Array<Map<T>: ConstDefault>>, T> ConstDefault for EnumMap<Ids, T>

Source§

const DEFAULT: Self

The constant default value.
Source§

impl<Ids: MapEnum<Array: Array<Map<T>: Copy>>, T> Copy for EnumMap<Ids, T>

Source§

impl<Ids: MapEnum<Array: Array<Map<T>: Debug>>, T> Debug for EnumMap<Ids, T>

Source§

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

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

impl<Ids: MapEnum<Array: Array<Map<T>: Default>>, T> Default for EnumMap<Ids, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<Ids: MapEnum<Array: Array<Map<T>: Eq>>, T> Eq for EnumMap<Ids, T>

Source§

impl<'i, Ids: MapEnum, T> Index<&'i Ids> for EnumMap<Ids, T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: &'i Ids) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<Ids: MapEnum, T> Index<Ids> for EnumMap<Ids, T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: Ids) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'i, Ids: MapEnum, T> IndexMut<&'i Ids> for EnumMap<Ids, T>

Source§

fn index_mut(&mut self, index: &'i Ids) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<Ids: MapEnum, T> IndexMut<Ids> for EnumMap<Ids, T>

Source§

fn index_mut(&mut self, index: Ids) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<Ids: MapEnum<Array: Array<Map<T>: Ord>>, T> Ord for EnumMap<Ids, T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<Ids: MapEnum<Array: Array<Map<T>: PartialEq>>, T> PartialEq for EnumMap<Ids, T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Ids: MapEnum<Array: Array<Map<T>: PartialOrd>>, T> PartialOrd for EnumMap<Ids, T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Ids: MapEnum<Array: Array<Map<T>: Pod>> + 'static, T: 'static> Pod for EnumMap<Ids, T>

Source§

impl<Ids: MapEnum, T: TransparentWrapper<U>, U> TransparentWrapper<EnumMap<Ids, U>> for EnumMap<Ids, T>

Source§

fn wrap(s: Inner) -> Self
where Self: Sized, Inner: Sized,

Convert the inner type into the wrapper type.
Source§

fn wrap_ref(s: &Inner) -> &Self

Convert a reference to the inner type into a reference to the wrapper type.
Source§

fn wrap_mut(s: &mut Inner) -> &mut Self

Convert a mutable reference to the inner type into a mutable reference to the wrapper type.
Source§

fn wrap_slice(s: &[Inner]) -> &[Self]
where Self: Sized, Inner: Sized,

Convert a slice to the inner type into a slice to the wrapper type.
Source§

fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]
where Self: Sized, Inner: Sized,

Convert a mutable slice to the inner type into a mutable slice to the wrapper type.
Source§

fn peel(s: Self) -> Inner
where Self: Sized, Inner: Sized,

Convert the wrapper type into the inner type.
Source§

fn peel_ref(s: &Self) -> &Inner

Convert a reference to the wrapper type into a reference to the inner type.
Source§

fn peel_mut(s: &mut Self) -> &mut Inner

Convert a mutable reference to the wrapper type into a mutable reference to the inner type.
Source§

fn peel_slice(s: &[Self]) -> &[Inner]
where Self: Sized, Inner: Sized,

Convert a slice to the wrapped type into a slice to the inner type.
Source§

fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]
where Self: Sized, Inner: Sized,

Convert a mutable slice to the wrapped type into a mutable slice to the inner type.
Source§

impl<Ids: MapEnum<Array: Array<Map<T>: Zeroable>>, T> Zeroable for EnumMap<Ids, T>

Source§

fn zeroed() -> Self

Auto Trait Implementations§

§

impl<Ids, T> Freeze for EnumMap<Ids, T>
where <<Ids as MapEnum>::Array as Array>::Map<T>: Freeze,

§

impl<Ids, T> RefUnwindSafe for EnumMap<Ids, T>
where <<Ids as MapEnum>::Array as Array>::Map<T>: RefUnwindSafe,

§

impl<Ids, T> Send for EnumMap<Ids, T>
where <<Ids as MapEnum>::Array as Array>::Map<T>: Send,

§

impl<Ids, T> Sync for EnumMap<Ids, T>
where <<Ids as MapEnum>::Array as Array>::Map<T>: Sync,

§

impl<Ids, T> Unpin for EnumMap<Ids, T>
where <<Ids as MapEnum>::Array as Array>::Map<T>: Unpin,

§

impl<Ids, T> UnsafeUnpin for EnumMap<Ids, T>
where <<Ids as MapEnum>::Array as Array>::Map<T>: UnsafeUnpin,

§

impl<Ids, T> UnwindSafe for EnumMap<Ids, T>
where <<Ids as MapEnum>::Array as Array>::Map<T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> AlignedRepr<T> for T

Source§

impl<T> AlterRepr<T> for T

Source§

const IS_SWEAP_BYTES: bool = const IS_SWEAP_BYTES: bool = false;

Source§

fn from_std_repr(v: T) -> T

Source§

fn into_std_repr(src: T) -> T

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> AnyBitPattern for T
where T: Pod,

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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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> NoUninit for T
where T: Pod,

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.