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>
impl<T> VecOption<T>
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates an empty vector
allocates at least cap
elements of space
Sourcepub fn reserve(&mut self, amount: usize)
pub fn reserve(&mut self, amount: usize)
reserves at least amount
elements
if there is already enough space, this does nothing
Sourcepub fn reserve_exact(&mut self, amount: usize)
pub fn reserve_exact(&mut self, amount: usize)
reserves exactly amount
elements
if there is already enough space, this does nothing
Sourcepub fn capacity(&self) -> CapacityInfo
pub fn capacity(&self) -> CapacityInfo
The capacity of the vector
Sourcepub fn push<V: Into<Option<T>>>(&mut self, value: V)
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
Sourcepub fn pop(&mut self) -> Option<Option<T>>
pub fn pop(&mut self) -> Option<Option<T>>
Remove the last element of the vector
returns None
if the vector is empty
Sourcepub fn get_mut(&mut self, index: usize) -> Option<OptionProxy<'_, T>>
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.
Sourcepub fn get(&self, index: usize) -> Option<Option<&T>>
pub fn get(&self, index: usize) -> Option<Option<&T>>
Returns a reference to the element at index
or None if out of bounds.
Sourcepub fn swap(&mut self, a: usize, b: usize)
pub fn swap(&mut self, a: usize, b: usize)
Swaps two elements of the vector, panics if either index is out of bounds
Sourcepub fn take(&mut self, index: usize) -> Option<Option<T>>
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.
Sourcepub fn replace<O: Into<Option<T>>>(
&mut self,
index: usize,
value: O,
) -> Option<Option<T>>
pub fn replace<O: Into<Option<T>>>( &mut self, index: usize, value: O, ) -> Option<Option<T>>
Replace the element at index
with value
Sourcepub fn truncate(&mut self, len: usize)
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
Sourcepub fn set_all_none(&mut self)
pub fn set_all_none(&mut self)
Sets all of the elements in the vector to None
and drops
all values in the closure
Sourcepub fn extend_none(&mut self, additional: usize)
pub fn extend_none(&mut self, additional: usize)
Extends the vector with additional
number of None
s
Sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
returns an iterator over references to the elements in the vector
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
returns an iterator over mutable references to the elements in the vector
Sourcepub 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>
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>
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
Sourcepub fn fold<Range, A, F: FnMut(A, usize, &mut Option<T>) -> A>(
&mut self,
range: Range,
init: A,
f: F,
) -> A
pub fn fold<Range, A, F: FnMut(A, usize, &mut Option<T>) -> A>( &mut self, range: Range, init: A, f: F, ) -> A
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
Sourcepub fn try_for_each<Range, B, F: FnMut(usize, &mut Option<T>) -> Result<(), B>>(
&mut self,
range: Range,
f: F,
) -> Result<(), B>
pub fn try_for_each<Range, B, F: FnMut(usize, &mut Option<T>) -> Result<(), B>>( &mut self, range: Range, f: F, ) -> Result<(), B>
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
Sourcepub fn for_each<Range, F: FnMut(usize, &mut Option<T>)>(
&mut self,
range: Range,
f: F,
)
pub fn for_each<Range, F: FnMut(usize, &mut Option<T>)>( &mut self, range: Range, f: F, )
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> Extend<Option<T>> for VecOption<T>
impl<T> Extend<Option<T>> for VecOption<T>
Source§fn extend<I: IntoIterator<Item = Option<T>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Option<T>>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<T> Extend<T> for VecOption<T>
impl<T> Extend<T> for VecOption<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)