Struct VecOption

Source
pub struct VecOption<T> { /* private fields */ }
Expand description

A space optimized version of Vec<Option<T>> that stores the discriminant seperately

See crate-level docs for more information

Implementations§

Source§

impl<T> VecOption<T>

Source

pub fn new() -> Self

Creates an empty vector, does not allocate

Source

pub fn with_capacity(cap: usize) -> Self

Creates an empty vector

allocates at least cap elements of space

Source

pub fn reserve(&mut self, amount: usize)

reserves at least amount elements

if there is already enough space, this does nothing

Source

pub fn reserve_exact(&mut self, amount: usize)

reserves exactly amount elements

if there is already enough space, this does nothing

Source

pub fn len(&self) -> usize

The length of this vector

Source

pub fn capacity(&self) -> CapacityInfo

The capacity of the vector

Source

pub fn is_empty(&self) -> bool

Is this vector empty

Source

pub fn push<V: Into<Option<T>>>(&mut self, value: V)

Put a value at the end of the vector

Reallocates if there is not enough space

Source

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

Remove the last element of the vector

returns None if the vector is empty

Source

pub fn get_mut(&mut self, index: usize) -> Option<OptionProxy<'_, T>>

Returns a proxy to a mutable reference to the element at index or None if out of bounds.

Source

pub fn get(&self, index: usize) -> Option<Option<&T>>

Returns a reference to the element at index or None if out of bounds.

Source

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

Swaps two elements of the vector, panics if either index is out of bounds

Source

pub fn take(&mut self, index: usize) -> Option<Option<T>>

Returns the element at index or None if out of bounds.

Replaces the element at index with None.

Source

pub fn replace<O: Into<Option<T>>>( &mut self, index: usize, value: O, ) -> Option<Option<T>>

Replace the element at index with value

Source

pub fn truncate(&mut self, len: usize)

Reduces the length of the vector to len and drops all excess elements

If len is greater than the length of the vector, nothing happens

Source

pub fn clear(&mut self)

Clears the vector

Source

pub fn set_all_none(&mut self)

Sets all of the elements in the vector to None and drops all values in the closure

Source

pub fn extend_none(&mut self, additional: usize)

Extends the vector with additional number of Nones

Source

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

returns an iterator over references to the elements in the vector

Source

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

returns an iterator over mutable references to the elements in the vector

Source

pub fn try_fold<Range, A, B, F: FnMut(A, usize, &mut Option<T>) -> Result<A, B>>( &mut self, range: Range, init: A, f: F, ) -> Result<A, B>
where Range: SliceIndex<[MaybeUninit<T>], Output = [MaybeUninit<T>]> + RangeBounds<usize>,

Iterates over all of the Option<T>s in the vector and applies the closure to each one of them until the closure returns Err(..), then iteration ends

The closure is passed the init, index, and a mutable reference to the corrosponding element of the vector

This is similar to Iterator::try_fold

Source

pub fn fold<Range, A, F: FnMut(A, usize, &mut Option<T>) -> A>( &mut self, range: Range, init: A, f: F, ) -> A
where Range: SliceIndex<[MaybeUninit<T>], Output = [MaybeUninit<T>]> + RangeBounds<usize>,

Iterates over all of the Option<T>s in the vector and applies the closure to each one

The closure is passed the init, index, and a mutable reference to the corrosponding element of the vector

This is similar to Iterator::fold

Source

pub fn try_for_each<Range, B, F: FnMut(usize, &mut Option<T>) -> Result<(), B>>( &mut self, range: Range, f: F, ) -> Result<(), B>
where Range: SliceIndex<[MaybeUninit<T>], Output = [MaybeUninit<T>]> + RangeBounds<usize>,

Iterates over all of the Option<T>s in the vector and applies the closure to each one of them until the closure returns Err(..), then iteration ends

The closure is passed the index, and a mutable reference to the corrosponding element of the vector

This is similar to Iterator::try_for_each

Source

pub fn for_each<Range, F: FnMut(usize, &mut Option<T>)>( &mut self, range: Range, f: F, )
where Range: SliceIndex<[MaybeUninit<T>], Output = [MaybeUninit<T>]> + RangeBounds<usize>,

Iterates over all of the Option<T>s in the vector and applies the closure to each one

The closure is passed the index, and a mutable reference to the corrosponding element of the vector

This is similar to Iterator::for_each

Trait Implementations§

Source§

impl<T: Clone> Clone for VecOption<T>

Source§

fn clone(&self) -> Self

Returns a duplicate 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> Debug for VecOption<T>

Source§

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

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

impl<T> Default for VecOption<T>

Source§

fn default() -> Self

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

impl<T> Drop for VecOption<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Extend<Option<T>> for VecOption<T>

Source§

fn extend<I: IntoIterator<Item = Option<T>>>(&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> Extend<T> for VecOption<T>

Source§

fn extend<I: IntoIterator<Item = T>>(&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> From<Vec<Option<T>>> for VecOption<T>

Source§

fn from(vec: Vec<Option<T>>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for VecOption<T>

Source§

fn from(vec: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> FromIterator<Option<T>> for VecOption<T>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T: Hash> Hash for VecOption<T>

Source§

fn hash<H: Hasher>(&self, hasher: &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> IntoIterator for &'a VecOption<T>

Source§

type Item = Option<&'a T>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

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> IntoIterator for &'a mut VecOption<T>

Source§

type Item = OptionProxy<'a, T>

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

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> IntoIterator for VecOption<T>

Source§

type Item = Option<T>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

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: Ord> Ord for VecOption<T>

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl<T: PartialEq> PartialEq<[T]> for VecOption<T>

Source§

fn eq(&self, other: &[T]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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: PartialEq, S: AsRef<[Option<T>]>> PartialEq<S> for VecOption<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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: PartialEq> PartialEq for VecOption<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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: PartialOrd> PartialOrd for VecOption<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 · 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 · 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 · 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 · 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<T: Eq> Eq for VecOption<T>

Auto Trait Implementations§

§

impl<T> Freeze for VecOption<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for VecOption<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> 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> ToOwned for T
where T: Clone,

Source§

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

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.