Skip to main content

EnumOptionMap

Struct EnumOptionMap 

Source
pub struct EnumOptionMap<T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord>, V, BitsetWord: BitsetWordTrait = u8> { /* private fields */ }
Expand description

A partial map from enumoid T to values V.

The optional type parameter BitsetWord is passed on to an embedded EnumSet which is used to store the validity bitmap.

Implementations§

Source§

impl<T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord>, V, BitsetWord: BitsetWordTrait> EnumOptionMap<T, V, BitsetWord>

Source

pub fn new() -> Self

Creates a new empty map.

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 has no value in the map.

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 has no value in the map.

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 has no value in the map.

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 has no value in the map.

Source

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

Sets the value associated with a given index and returns the old value if one was present.

Source

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

Sets the value associated with a given key and returns the old value if one was present.

Source

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

Adds a value at the given index to the map and returns the old value if one was present.

Source

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

Adds a value with the given key to the map and returns the old value if one was present.

Source

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

Removes any value at the given index from the map and returns it if one was present.

Source

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

Removes any value with the given key from the map and returns it if one was present.

Source

pub fn swap_by_index(&mut self, a: EnumIndex<T>, b: EnumIndex<T>)

Swaps two elements in the map by index.

Source

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

Swaps two elements in the map.

Source

pub fn clear(&mut self)

Clears all the elements from the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map is empty.

Source

pub fn is_full(&self) -> bool

Returns true if the map is fully populated.

Source

pub fn is_vec(&self) -> Option<EnumSize<T>>

Returns the size of a vector needed to represent the map, or None if the map is not representable by a vector.

A map is representable by vector if all the populated values are contiguous with the first key, or if the map is empty.

Source

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

Returns true if the map contains the index.

Source

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

Returns true if the map contains the key.

Source

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

Returns an iterator over the keys and values.

Source

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

Returns a mutable iterator over the keys and values.

Source

pub fn count(&self) -> usize

Returns the number of populated keys in the map.

Source

pub fn keys(&self) -> &EnumSet<T, BitsetWord>

Returns a reference to the set of populated keys.

Trait Implementations§

Source§

impl<T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord> + Debug, V: Debug, BitsetWord: BitsetWordTrait> Debug for EnumOptionMap<T, V, BitsetWord>

Source§

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

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

impl<T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord>, V, BitsetWord: BitsetWordTrait> Default for EnumOptionMap<T, V, BitsetWord>

Source§

fn default() -> Self

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

impl<'de, T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord> + Deserialize<'de>, V: Deserialize<'de>, BitsetWord: BitsetWordTrait> Deserialize<'de> for EnumOptionMap<T, V, BitsetWord>

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> + EnumSetHelper<BitsetWord>, V, BitsetWord: BitsetWordTrait> Drop for EnumOptionMap<T, V, BitsetWord>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord>, V: Eq, BitsetWord: BitsetWordTrait> Eq for EnumOptionMap<T, V, BitsetWord>

Source§

impl<T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord>, V, BitsetWord: BitsetWordTrait> Extend<(T, V)> for EnumOptionMap<T, V, BitsetWord>

Source§

fn extend<I: IntoIterator<Item = (T, V)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord>, V, BitsetWord: BitsetWordTrait> FromIterator<(T, V)> for EnumOptionMap<T, V, BitsetWord>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord>, V: Hash, BitsetWord: BitsetWordTrait> Hash for EnumOptionMap<T, V, BitsetWord>

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<'a, T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord>, V, BitsetWord: BitsetWordTrait> IntoIterator for &'a EnumOptionMap<T, V, BitsetWord>

Source§

type Item = (T, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = EnumOptionMapIter<'a, T, V, BitsetWord>

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<'a, T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord>, V, BitsetWord: BitsetWordTrait> IntoIterator for &'a mut EnumOptionMap<T, V, BitsetWord>

Source§

type Item = (T, &'a mut V)

The type of the elements being iterated over.
Source§

type IntoIter = EnumOptionMapIterMut<'a, T, V, BitsetWord>

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> + EnumSetHelper<BitsetWord>, V, BitsetWord: BitsetWordTrait> IntoIterator for EnumOptionMap<T, V, BitsetWord>

Source§

type Item = (T, V)

The type of the elements being iterated over.
Source§

type IntoIter = EnumOptionMapIntoIter<T, V, BitsetWord>

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> + EnumSetHelper<BitsetWord>, V: PartialEq, BitsetWord: BitsetWordTrait> PartialEq for EnumOptionMap<T, V, BitsetWord>

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<T: EnumArrayHelper<V> + EnumSetHelper<BitsetWord> + Serialize, V: Serialize, BitsetWord: BitsetWordTrait> Serialize for EnumOptionMap<T, V, BitsetWord>

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 EnumMap<T, V>

Source§

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> + EnumSetHelper<u8>, V> TryFrom<EnumOptionMap<T, V>> for EnumVec<T, V>

Source§

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.

Auto Trait Implementations§

§

impl<T, V, BitsetWord> Freeze for EnumOptionMap<T, V, BitsetWord>
where <T as EnumArrayHelper<V>>::PartialArray: Freeze, <T as EnumSetHelper<BitsetWord>>::BitsetArray: Freeze,

§

impl<T, V, BitsetWord> RefUnwindSafe for EnumOptionMap<T, V, BitsetWord>
where <T as EnumArrayHelper<V>>::PartialArray: RefUnwindSafe, <T as EnumSetHelper<BitsetWord>>::BitsetArray: RefUnwindSafe,

§

impl<T, V, BitsetWord> Send for EnumOptionMap<T, V, BitsetWord>
where <T as EnumArrayHelper<V>>::PartialArray: Send, <T as EnumSetHelper<BitsetWord>>::BitsetArray: Send,

§

impl<T, V, BitsetWord> Sync for EnumOptionMap<T, V, BitsetWord>
where <T as EnumArrayHelper<V>>::PartialArray: Sync, <T as EnumSetHelper<BitsetWord>>::BitsetArray: Sync,

§

impl<T, V, BitsetWord> Unpin for EnumOptionMap<T, V, BitsetWord>
where <T as EnumArrayHelper<V>>::PartialArray: Unpin, <T as EnumSetHelper<BitsetWord>>::BitsetArray: Unpin,

§

impl<T, V, BitsetWord> UnsafeUnpin for EnumOptionMap<T, V, BitsetWord>
where <T as EnumArrayHelper<V>>::PartialArray: UnsafeUnpin, <T as EnumSetHelper<BitsetWord>>::BitsetArray: UnsafeUnpin,

§

impl<T, V, BitsetWord> UnwindSafe for EnumOptionMap<T, V, BitsetWord>
where <T as EnumArrayHelper<V>>::PartialArray: UnwindSafe, <T as EnumSetHelper<BitsetWord>>::BitsetArray: 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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