Struct option_vec::OptionVec
[−]
[src]
pub struct OptionVec<T> { /* fields omitted */ }
An abstraction over Vec<Option<T>>
An element in an OptionVec<T>
can be accessed by index and maintains
its position when elements are removed from the container.
An element inserted into an OptionVec<T>
will occupy the first available
position in the container.
Methods
impl<T> OptionVec<T>
[src]
fn new() -> OptionVec<T>
Creates an empty OptionVec<T>
.
fn with_capacity(n: usize) -> OptionVec<T>
Creates an empty OptionVec<T>
with capacity for n
elements.
fn inner(&self) -> &Vec<Option<T>>
Returns a borrowed reference to the internal Vec<Option<T>>
.
fn inner_mut(&mut self) -> &mut Vec<Option<T>>
Returns a mutable reference to the internal Vec<Option<T>>
.
Modification of this internal container is safe, but using methods
such as Vec::insert
or Vec::remove
will invalidate existing indices.
fn capacity(&self) -> usize
Returns the allocated capacity for elements.
fn len(&self) -> usize
Returns the number of contained elements.
This operation is O(N)
, as all non-None
elements must be individually
counted.
fn is_empty(&self) -> bool
Returns whether the container is empty.
This operation is O(N)
worst-case, as any elements must be searched
for a non-None
element.
fn insert(&mut self, t: T) -> usize
Inserts an element into the first available position, returning the destination position.
fn remove(&mut self, idx: usize) -> Option<T>
Removes an element from the given position, if one exists.
fn reserve(&mut self, n: usize)
Reserves capacity for at least n
more elements.
fn reserve_exact(&mut self, n: usize)
Reserves capacity for exactly n
more elements.
fn shrink_to_fit(&mut self)
Shrinks the allocation as much as possible.
Any trailing None
elements will be truncated. None
elements in
internal positions are not removed, so as to maintain Some(_)
element
positions.
fn retain<F>(&mut self, f: F) where F: FnMut(&mut T) -> bool
Retains only elements specified by the predicate.
All elements e
such that f(&mut e)
returns false
will be assigned
to None
.
fn pop_back(&mut self) -> Option<T>
Removes and returns the last occupied element.
fn pop_front(&mut self) -> Option<T>
Removes and returns the first occupied element.
fn clear(&mut self)
Removes all contained elements.
fn contains(&self, idx: usize) -> bool
Returns whether an element exists at the given index.
fn get(&self, idx: usize) -> Option<&T>
Returns an element at the given position.
fn get_mut(&mut self, idx: usize) -> Option<&mut T>
Returns a mutable reference to an element at the given position.
fn iter(&self) -> Iter<T>
Returns an iterator over contained elements.
fn iter_mut(&mut self) -> IterMut<T>
Returns an iterator over mutable references to contained elements.
fn into_enumerate(self) -> IntoEnumerate<T>
Returns an iterator over values with indices.
The elements yielded by this iterator will be (usize, T)
.
fn enumerate(&self) -> Enumerate<T>
Returns an iterator over references with indices.
The elements yielded by this iterator will be (usize, &T)
.
fn enumerate_mut(&mut self) -> EnumerateMut<T>
Returns an iterator over mutable references with indices.
The elements yielded by this iterator will be (usize, &mut T)
.
Trait Implementations
impl<T: Debug> Debug for OptionVec<T>
[src]
impl<T: Clone> Clone for OptionVec<T>
[src]
fn clone(&self) -> OptionVec<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, other: &OptionVec<T>)
Performs copy-assignment from source
. Read more
impl<T> Default for OptionVec<T>
[src]
impl<T> From<Vec<Option<T>>> for OptionVec<T>
[src]
impl<T> Into<Vec<Option<T>>> for OptionVec<T>
[src]
impl<T> Extend<T> for OptionVec<T>
[src]
fn extend<I>(&mut self, iter: I) where I: IntoIterator<Item=T>
Extends a collection with the contents of an iterator. Read more
impl<T> FromIterator<T> for OptionVec<T>
[src]
fn from_iter<I>(iter: I) -> OptionVec<T> where I: IntoIterator<Item=T>
Creates a value from an iterator. Read more
impl<'b, A, B> PartialEq<OptionVec<B>> for OptionVec<A> where A: PartialEq<B>
[src]
fn eq(&self, rhs: &OptionVec<B>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, rhs: &OptionVec<B>) -> bool
This method tests for !=
.
impl<'b, A, B> PartialEq<Vec<B>> for OptionVec<A> where A: PartialEq<B>
[src]
fn eq(&self, rhs: &Vec<B>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, rhs: &Vec<B>) -> bool
This method tests for !=
.
impl<'b, A, B> PartialEq<&'b [B]> for OptionVec<A> where A: PartialEq<B>
[src]
fn eq(&self, rhs: &&'b [B]) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, rhs: &&'b [B]) -> bool
This method tests for !=
.
impl<T> Eq for OptionVec<T> where T: Eq
[src]
impl<T> PartialOrd for OptionVec<T> where T: PartialOrd
[src]
fn partial_cmp(&self, rhs: &OptionVec<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, rhs: &OptionVec<T>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, rhs: &OptionVec<T>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, rhs: &OptionVec<T>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, rhs: &OptionVec<T>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T> Ord for OptionVec<T> where T: Ord
[src]
fn cmp(&self, rhs: &OptionVec<T>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<T> Index<usize> for OptionVec<T>
[src]
type Output = T
The returned type after indexing
fn index(&self, idx: usize) -> &T
The method for the indexing (container[index]
) operation
impl<T> IndexMut<usize> for OptionVec<T>
[src]
fn index_mut(&mut self, idx: usize) -> &mut T
The method for the mutable indexing (container[index]
) operation
impl<T> IntoIterator for OptionVec<T>
[src]
type Item = 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) -> IntoIter<T>
Creates an iterator from a value. Read more
impl<'a, T> IntoIterator for &'a OptionVec<T>
[src]
type Item = &'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) -> Iter<'a, T>
Creates an iterator from a value. Read more