OptionVec

Struct OptionVec 

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

A vector that can contain unused indices.

Implementations§

Source§

impl<T> OptionVec<T>

Source

pub fn new() -> Self

Create a new OptionVec with no elements.

Source

pub fn len(&self) -> usize

Source

pub fn size(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn contains(&self, index: usize) -> bool

Source

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

Source

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

Source

pub fn capacity(&self) -> usize

Source

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

Source

pub fn clear(&mut self)

Source

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

Source

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

Source

pub fn insert(&mut self, index: usize, element: T)

Write the element at the given index. If there is already an element at the given index, it will be overwritten. If there isn’t, a new element will be added at that index.

Source

pub fn try_remove(&mut self, index: usize) -> Result<T, String>

Remove the element at the given index and return it. If the OptionVec is not big enough to contain this index, this will throw an error. If there isn’t an element at that index, this will throw an error.

Source

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

Source

pub fn remove(&mut self, index: usize) -> T

Remove the element at the given index and return it. If the OptionVec is not big enough to contain this index, this will panic. If there isn’t an element at that index, this will panic.

Trait Implementations§

Source§

impl<T: Clone> Clone for OptionVec<T>

Source§

fn clone(&self) -> OptionVec<T>

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 OptionVec<T>

Source§

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

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

impl<T> Default for OptionVec<T>

Source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for OptionVec<T>
where T: Deserialize<'de>,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'de, T> Deserialize<'de> for OptionVec<T>
where T: Deserialize<'de>,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, DeError>
where D: DeserializerTrait<'de>,

Deserialize this value from the given deserializer.
Source§

impl<T> Extend<(usize, T)> for OptionVec<T>

Source§

fn extend<I: IntoIterator<Item = (usize, T)>>(&mut self, iterable: 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> FromIterator<(usize, T)> for OptionVec<T>

Source§

fn from_iter<I: IntoIterator<Item = (usize, T)>>(iterable: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> Index<usize> for OptionVec<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for OptionVec<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T> IntoIterator for &'a OptionVec<T>

Source§

type Item = (usize, &'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 OptionVec<T>

Source§

type Item = (usize, &'a mut 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: PartialEq> PartialEq for OptionVec<T>

Source§

fn eq(&self, other: &OptionVec<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> Serialize for OptionVec<T>
where T: Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Serialize for OptionVec<T>
where T: Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, SerError>
where S: SerializerTrait,

Serialize this value into the given serializer.
Source§

impl<T: Eq> Eq for OptionVec<T>

Source§

impl<T> StructuralPartialEq for OptionVec<T>

Auto Trait Implementations§

§

impl<T> Freeze for OptionVec<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for OptionVec<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,