ValueVec

Struct ValueVec 

Source
pub struct ValueVec<V: Copy> { /* private fields */ }
Expand description

A by-value, ref-less vector with interior mutability. Values of type V can be moved into and out of the vector. We require V to be Copy to avoid subtle soundness issues.

Implementations§

Source§

impl<V: Copy> ValueVec<V>

Source

pub fn new() -> Self

Creates an empty ValueVec.

Source

pub fn with_capacity(cap: usize) -> Self

Creates with capacity.

Source

pub fn len(&self) -> usize

Current number of elements.

Source

pub fn capacity(&self) -> usize

Current capacity of the backing Vec.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector has no elements.

Source

pub fn reserve(&self, additional: usize)

Ensures capacity for at least additional more elements.

Source

pub fn shrink_to_fit(&self)

Shrinks the capacity as much as possible.

Source

pub fn push(&self, value: V)

Pushes a value (by move) onto the end.

Source

pub fn pop(&self) -> Option<V>

Pops and returns the last element (by move), or None if empty.

Source

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

Returns the value of the element at index, if index is in range. Returns None if index is out of bounds. This is a bounds-checked variant of ValueVec::at.

Source

pub fn at(&self, index: usize) -> V

Returns the value at index. Panics if index is out of bounds.

Use ValueVec::get for a bounds-checked version of this method.

Source

pub fn replace(&self, index: usize, value: V) -> V

Moves a value into the slot at index, returning the old value (via move). Panics if index is out of bounds.

Source

pub fn set(&self, index: usize, value: V)

Sets the value of the slot at index to value. Panics if index is out of bounds.

Source

pub fn swap_value(&self, index: usize, value: &mut V)

Swaps the value at index with the provided one in place. Panics if index is out of bounds.

The existing value ends up in *value.

Source

pub fn insert(&self, index: usize, value: V)

Inserts value at position index, shifting elements to the right. Panics if index is out of bounds.

Source

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

Removes and returns the element at index, shifting elements left. Panics if index is out of bounds.

Source

pub fn swap_remove(&self, index: usize) -> V

Removes and returns the element at index by swapping in the last element.

O(1) removal when order does not matter.

Source

pub fn contains(&self, value: &V) -> bool
where V: PartialEq,

Returns true if the ValueVec contains an element with the given value.

Source

pub fn clear(&self)

Clears all elements.

Source

pub fn extend<I>(&self, iter: I)
where I: IntoIterator<Item = V>,

Extends the vector by moving in elements from an iterator.

Source

pub fn resize(&self, new_len: usize, value: V)

Source

pub fn resize_with<F>(&self, new_len: usize, f: F)
where F: FnMut() -> V,

Source

pub fn to_vec(&self) -> Vec<V>
where V: Clone,

Returns a snapshot Vec<V> by cloning all elements.

Use From<ValueVec<V>> for Vec<V> for a zero-cost conversion if you don’t want to clone.

Trait Implementations§

Source§

impl<V: Copy + Debug> Debug for ValueVec<V>

Source§

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

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

impl<V: Copy> Default for ValueVec<V>

Source§

fn default() -> Self

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

impl<V: Copy> From<ValueVec<V>> for Vec<V>

Source§

fn from(val: ValueVec<V>) -> Self

Converts to this type from the input type.
Source§

impl<V: Copy> From<Vec<V>> for ValueVec<V>

Source§

fn from(src: Vec<V>) -> Self

Wraps an existing Vec without copying its elements.

Source§

impl<V: Copy> FromIterator<V> for ValueVec<V>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<V: Copy> IntoIterator for ValueVec<V>

Source§

type Item = V

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<V> !Freeze for ValueVec<V>

§

impl<V> !RefUnwindSafe for ValueVec<V>

§

impl<V> Send for ValueVec<V>
where V: Send,

§

impl<V> !Sync for ValueVec<V>

§

impl<V> Unpin for ValueVec<V>
where V: Unpin,

§

impl<V> UnwindSafe for ValueVec<V>
where V: 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
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> 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.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
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.
§

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

§

fn vzip(self) -> V