Struct enumoid::EnumVec

source ·
pub struct EnumVec<T: EnumArrayHelper<V>, V> { /* private fields */ }
Expand description

A vector of values V indexed by enumoid T.

Implementations§

source§

impl<T: EnumArrayHelper<V>, V> EnumVec<T, V>

source

pub fn new() -> Self

Creates a new vector with no elements.

source

pub fn new_with<F>(size: EnumSize<T>, f: F) -> Self
where F: FnMut(T) -> V,

Creates a new vector with a specified number of elements generated by a callback function.

source

pub fn as_slice(&self) -> &[V]

Returns a slice containing all the values in the vector.

source

pub fn as_slice_mut(&mut self) -> &mut [V]

Returns a mutable slice containing all the values in the vector.

source

pub fn get_by_index(&self, index: EnumIndex<T>) -> Option<&V>

Returns a reference to the value associated with a given index, or None if the index is beyond the end of the vector.

source

pub fn get(&self, key: T) -> Option<&V>

Returns a reference to the value associated with a given key, or None if the key is beyond the end of the vector.

source

pub fn get_by_index_mut(&mut self, index: EnumIndex<T>) -> Option<&mut V>

Returns a mutable reference to the value associated with a given index, or None if the index is beyond the end of the vector.

source

pub fn get_mut(&mut self, key: T) -> Option<&mut V>

Returns a mutable reference to the value associated with a given key, or None if the key is beyond the end of the vector.

source

pub fn is_empty(&self) -> bool

Returns true if the vector is empty.

source

pub fn is_full(&self) -> bool

Returns true if the vector is fully populated.

source

pub fn contains_index(&self, index: EnumIndex<T>) -> bool

Returns true if the vector contains the index.

source

pub fn contains(&self, value: T) -> bool

Returns true if the vector contains the key.

source

pub fn size(&self) -> EnumSize<T>

Returns the size of the vector.

source

pub fn swap(&mut self, a: T, b: T)

Swaps two elements in the vector.

§Panics

Panics if a or b are beyond the end of the vector.

source

pub fn swap_remove(&mut self, key: T) -> Option<V>

Removes an element and returns it, replacing it with the last element.

source

pub fn remove(&mut self, key: T) -> Option<V>

Removes an element and returns it.

source

pub fn clear(&mut self)

Clears all the elements from the vector.

source

pub fn push(&mut self, value: V)

Adds an element to the end of the vector.

§Panics

Panics if the vector is already full.

source

pub fn pop(&mut self) -> Option<V>

Removes an element from the end of the vector and returns it, or None if the vector is empty.

source

pub fn iter(&self) -> EnumSliceIter<'_, T, V>

Returns an iterator over the keys and elements.

source

pub fn iter_mut(&mut self) -> EnumSliceIterMut<'_, T, V>

Returns a mutable iterator over the keys and elements.

Trait Implementations§

source§

impl<T: EnumArrayHelper<V>, V: Clone> Clone for EnumVec<T, V>

source§

fn clone(&self) -> Self

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: EnumArrayHelper<V> + Debug, V: Debug> Debug for EnumVec<T, V>

source§

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

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

impl<T: EnumArrayHelper<V>, V> Default for EnumVec<T, V>

source§

fn default() -> Self

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

impl<'de, T: EnumArrayHelper<V> + EnumSetHelper<u8> + Deserialize<'de>, V: Deserialize<'de>> Deserialize<'de> for EnumVec<T, V>

source§

fn deserialize<D>(de: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: EnumArrayHelper<V>, V> Drop for EnumVec<T, V>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: EnumArrayHelper<V>, V> FromIterator<V> for EnumVec<T, V>

source§

fn from_iter<I: IntoIterator<Item = V>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T: EnumArrayHelper<V>, V: Hash> Hash for EnumVec<T, V>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: EnumArrayHelper<V>, V> Index<EnumIndex<T>> for EnumVec<T, V>

§

type Output = V

The returned type after indexing.
source§

fn index(&self, index: EnumIndex<T>) -> &V

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

impl<T: EnumArrayHelper<V>, V> Index<T> for EnumVec<T, V>

§

type Output = V

The returned type after indexing.
source§

fn index(&self, key: T) -> &V

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

impl<T: EnumArrayHelper<V>, V> IndexMut<EnumIndex<T>> for EnumVec<T, V>

source§

fn index_mut(&mut self, index: EnumIndex<T>) -> &mut V

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

impl<T: EnumArrayHelper<V>, V> IndexMut<T> for EnumVec<T, V>

source§

fn index_mut(&mut self, key: T) -> &mut V

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

impl<'a, T: EnumArrayHelper<V>, V> IntoIterator for &'a EnumVec<T, V>

§

type Item = (T, &'a V)

The type of the elements being iterated over.
§

type IntoIter = EnumSliceIter<'a, T, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: EnumArrayHelper<V>, V: PartialEq> PartialEq for EnumVec<T, V>

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: EnumArrayHelper<V> + Serialize, V: Serialize> Serialize for EnumVec<T, V>

source§

fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: EnumArrayHelper<V> + EnumSetHelper<u8>, V> TryFrom<EnumOptionMap<T, V>> for EnumVec<T, V>

§

type Error = ()

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

fn try_from(from: EnumOptionMap<T, V>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: EnumArrayHelper<V>, V: Eq> Eq for EnumVec<T, V>

Auto Trait Implementations§

§

impl<T, V> RefUnwindSafe for EnumVec<T, V>

§

impl<T, V> Send for EnumVec<T, V>
where <T as EnumArrayHelper<V>>::PartialArray: Send, <T as Enumoid>::Word: Send,

§

impl<T, V> Sync for EnumVec<T, V>
where <T as EnumArrayHelper<V>>::PartialArray: Sync, <T as Enumoid>::Word: Sync,

§

impl<T, V> Unpin for EnumVec<T, V>
where <T as EnumArrayHelper<V>>::PartialArray: Unpin, <T as Enumoid>::Word: Unpin,

§

impl<T, V> UnwindSafe for EnumVec<T, V>

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,