Struct enum_vec::EnumVec[][src]

pub struct EnumVec<T: EnumLike> { /* fields omitted */ }

A vector which efficiently stores enum variants.

Methods

impl<T: EnumLike> EnumVec<T>
[src]

Returns the number of elements that can be hold without allocating new memory.

use enum_vec::EnumVec;

let ev = EnumVec::<bool>::with_capacity(53);
assert!(ev.capacity() >= 53);

Reserves capacity for at least additional more elements.

use enum_vec::EnumVec;

let mut ev: EnumVec<Option<()>> = vec![None, None, None].into();
ev.reserve(100);
assert!(ev.capacity() >= 100 + 3);

Shrinks the capacity as much as possible.

Remove an element from an arbitrary position in O(1) time, but without preserving the ordering. This is accomplished by swapping the desired element with the last element, and then calling pop().

use enum_vec::EnumVec;

let mut ev: EnumVec<bool> = vec![true, true, true, false, false].into();
ev.swap_remove(0);
assert_eq!(&ev.to_vec(), &[false, true, true, false]);
ev.swap_remove(1);
assert_eq!(&ev.to_vec(), &[false, false, true]);

Insert and remove need a better implementation

Retains only the elements specified by the predicate

use enum_vec::EnumVec;

let mut v: EnumVec<(bool, bool)> = vec![(true, true), (false, false), (true, false),
    (false, true)].into();
v.retain(|x| x.0 == true);
let a = v.to_vec();
assert_eq!(&a, &[(true, true), (true, false)]);

Sets the length to zero, removing all the elements.

use enum_vec::EnumVec;

let mut ev = EnumVec::new();
ev.push(Some(false));
assert_eq!(ev.len(), 1);
ev.clear();
assert_eq!(ev.len(), 0);
assert!(ev.is_empty());

unsafe {
    ev.set_len(1);
    assert_eq!(ev.pop().unwrap(), Some(false));
}

Returns the length of the vector, the number of elements it holds.

Get the raw discriminant without bounds checking

Set the raw discriminant without bounds checking. It is assumed that the discriminant is lower than T::NUM_ELEMENTS.

Swap two elements.

Important traits for EnumVecIter<'a, T>

Apply a function to each element in place, this is a substitute to for loops:

use enum_vec::EnumVec;

let mut v = vec![true, false, true];
for x in v.iter_mut() {
    *x = !*x;
}

// Is equivalent to
let mut ev: EnumVec<_> = vec![true, false, true].into();
ev.for_each(|x| {
    *x = !*x;
});

assert_eq!(v, ev.to_vec());
assert_eq!(&v, &[false, true, false]);

Copies self into a plain Vec.

use enum_vec::EnumVec;

let mut ev = EnumVec::new();
ev.push(true);
ev.push(false);
let v = vec![true, false];
assert_eq!(ev.to_vec(), v);

Trait Implementations

impl<T: Clone + EnumLike> Clone for EnumVec<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: EnumLike + Debug> Debug for EnumVec<T>
[src]

Formats the value using the given formatter. Read more

impl<T: EnumLike> Default for EnumVec<T>
[src]

Returns the "default value" for a type. Read more

impl<T: EnumLike> Extend<T> for EnumVec<T>
[src]

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

impl<T: EnumLike> FromIterator<T> for EnumVec<T>
[src]

Creates a value from an iterator. Read more

impl<T: EnumLike> From<Vec<T>> for EnumVec<T>
[src]

Performs the conversion.

impl<T: EnumLike> Into<Vec<T>> for EnumVec<T>
[src]

Performs the conversion.

impl<'a, T: EnumLike> IntoIterator for &'a EnumVec<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<T: EnumLike> IntoIterator for EnumVec<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<T: EnumLike> PartialEq for EnumVec<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: EnumLike> Eq for EnumVec<T>
[src]

impl<T: EnumLike> Hash for EnumVec<T>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl<T> Send for EnumVec<T> where
    T: Send

impl<T> Sync for EnumVec<T> where
    T: Sync