[−][src]Struct vec_option::VecOption
A space optimized version of Vec<Option<T>>
that stores the discriminant seperately
Pros
- Can have a smaller memory footprint compared to
Vec<Option<T>>
ifOption<T>
's space optimizations don't take effect - Quickly set the entire collection to contain
None
- Fast extend with
None
Cons
- 2 allocations, instead of a single allocation
- Cannot remove elements from the middle of the vector
- Cannot work on the option's directly
Methods
impl<T> VecOption<T>
[src]
pub fn new() -> Self
[src]
Creates an empty vector, does not allocate
pub fn with_capacity(cap: usize) -> Self
[src]
Creates an empty vector
allocates at least cap
elements of space
pub fn reserve(&mut self, amount: usize)
[src]
reserves at least amount
elements
if there is already enough space, this does nothing
pub fn reserve_exact(&mut self, amount: usize)
[src]
reserves exactly amount
elements
if there is already enough space, this does nothing
pub fn len(&self) -> usize
[src]
The length of this vector
pub fn is_empty(&self) -> bool
[src]
Is this vector empty
pub fn push<V: Into<Option<T>>>(&mut self, value: V)
[src]
Put a value at the end of the vector
Reallocates if there is not enough space
pub fn pop(&mut self) -> Option<Option<T>>
[src]
Remove the last element of the vector
returns None
if the vector is empty
pub fn get_mut(&mut self, index: usize) -> Option<Option<&mut T>>
[src]
Returns a mutable reference to the element at index
or None if out of bounds.
pub fn get(&self, index: usize) -> Option<Option<&T>>
[src]
Returns a reference to the element at index
or None if out of bounds.
pub fn with_mut<F: FnOnce(&mut Option<T>) -> R, R>(
&mut self,
index: usize,
f: F
) -> Option<R>
[src]
&mut self,
index: usize,
f: F
) -> Option<R>
Yields a mutable reference to the Option
to the closure, and updates the value in the vector
once the closure completes, if the closure panics, the element will be in the None
state
pub fn swap(&mut self, a: usize, b: usize)
[src]
Swaps two elements of the vector, panics if either index is out of bounds
pub fn take(&mut self, index: usize) -> Option<Option<T>>
[src]
Returns the element at index
or None if out of bounds.
Replaces the element at index
with None.
pub fn replace<O: Into<Option<T>>>(
&mut self,
index: usize,
value: O
) -> Option<Option<T>>
[src]
&mut self,
index: usize,
value: O
) -> Option<Option<T>>
Replace the element at index
with value
pub fn truncate(&mut self, len: usize)
[src]
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
pub fn clear(&mut self)
[src]
Clears the vector
pub fn set_all_none(&mut self)
[src]
Sets all of the elements in the vector to None
and drops
all values in the closure
pub fn extend_none(&mut self, additional: usize)
[src]
Extends the vector with additional
number of None
s
ⓘImportant traits for Iter<'a, T>pub fn iter(&self) -> Iter<T>
[src]
returns an iterator over references to the elements in the vector
ⓘImportant traits for IterMut<'a, T>pub fn iter_mut(&mut self) -> IterMut<T>
[src]
returns an iterator over mutable references to the elements in the vector
pub fn try_fold<A, B, F: FnMut(A, usize, &mut Option<T>) -> Result<A, B>>(
&mut self,
init: A,
f: F
) -> Result<A, B>
[src]
&mut self,
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
pub fn fold<A, F: FnMut(A, usize, &mut Option<T>) -> A>(
&mut self,
init: A,
f: F
) -> A
[src]
&mut self,
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
pub fn try_for_each<B, F: FnMut(usize, &mut Option<T>) -> Result<(), B>>(
&mut self,
f: F
) -> Result<(), B>
[src]
&mut self,
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
pub fn for_each<F: FnMut(usize, &mut Option<T>)>(&mut self, f: F)
[src]
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
impl<T: Clone> Clone for VecOption<T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: Ord> Ord for VecOption<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl<T> Default for VecOption<T>
[src]
impl<T> IntoIterator for VecOption<T>
[src]
type Item = Option<T>
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a mut VecOption<T>
[src]
type Item = Option<&'a mut T>
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a VecOption<T>
[src]
type Item = Option<&'a T>
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T> From<Vec<T>> for VecOption<T>
[src]
impl<T> From<Vec<Option<T>>> for VecOption<T>
[src]
impl<T> Extend<Option<T>> for VecOption<T>
[src]
fn extend<I: IntoIterator<Item = Option<T>>>(&mut self, iter: I)
[src]
impl<T> Extend<T> for VecOption<T>
[src]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
impl<T: PartialOrd> PartialOrd<VecOption<T>> for VecOption<T>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T: PartialEq> PartialEq<VecOption<T>> for VecOption<T>
[src]
fn eq(&self, other: &Self) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<T: PartialEq> PartialEq<[T]> for VecOption<T>
[src]
fn eq(&self, other: &[T]) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<T: PartialEq, S: AsRef<[Option<T>]>> PartialEq<S> for VecOption<T>
[src]
fn eq(&self, other: &S) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<T> Drop for VecOption<T>
[src]
impl<T: Eq> Eq for VecOption<T>
[src]
impl<T: Debug> Debug for VecOption<T>
[src]
impl<T: Hash> Hash for VecOption<T>
[src]
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T> FromIterator<Option<T>> for VecOption<T>
[src]
fn from_iter<I: IntoIterator<Item = Option<T>>>(iter: I) -> Self
[src]
Auto Trait Implementations
impl<T> Sync for VecOption<T> where
T: Sync,
T: Sync,
impl<T> Send for VecOption<T> where
T: Send,
T: Send,
impl<T> Unpin for VecOption<T> where
T: Unpin,
T: Unpin,
impl<T> RefUnwindSafe for VecOption<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> UnwindSafe for VecOption<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,