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

A heap allocated, mutable contiguous buffer containing elements of type T.

Similar in principle to a Vec<T>. It can be converted for free into an immutable SharedVector<T> or AtomicSharedVector<T>.

Unique and shared vectors expose similar functionality. UniqueVector takes advantage of the guaranteed uniqueness at the type level to provide overall faster operations than its shared counterparts, while its memory layout makes it very cheap to convert to a shared vector (involving not allocation or copy).

Internal representation

UniqueVector stores its length and capacity inline and points to the first element of the allocated buffer. Room for a 16 bytes header is left before the first element so that the vector can be converted into a SharedVector or AtomicSharedVector without reallocating the storage.

Implementations§

source§

impl<T> UniqueVector<T>

source

pub fn new() -> Self

Creates an empty vector.

This does not allocate memory.

source

pub fn with_capacity(cap: usize) -> Self

Creates an empty pre-allocated vector with a given storage capacity.

Does not allocate memory if cap is zero.

source

pub fn try_with_capacity(cap: usize) -> Result<Self, AllocError>

Creates an empty pre-allocated vector with a given storage capacity.

Does not allocate memory if cap is zero.

source

pub fn from_slice(data: &[T]) -> Selfwhere T: Clone,

source

pub fn from_elem(elem: T, n: usize) -> Selfwhere T: Clone,

Creates a vector with n copies of elem.

source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

source

pub fn len(&self) -> usize

Returns the number of elements in the vector, also referred to as its ‘length’.

source

pub fn capacity(&self) -> usize

Returns the total number of elements the vector can hold without reallocating.

source

pub fn remaining_capacity(&self) -> usize

Returns number of elements that can be added without reallocating.

source

pub fn into_shared(self) -> SharedVector<T>

Make this vector immutable.

This operation is cheap, the underlying storage does not not need to be reallocated.

source

pub fn into_shared_atomic(self) -> AtomicSharedVector<T>

Make this vector immutable.

This operation is cheap, the underlying storage does not not need to be reallocated.

source

pub fn as_slice(&self) -> &[T]

source

pub fn as_mut_slice(&mut self) -> &mut [T]

source

pub fn iter(&self) -> impl Iterator<Item = &T>

source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>

source

pub fn first(&self) -> Option<&T>

source

pub fn last(&self) -> Option<&T>

source

pub fn first_mut(&mut self) -> Option<&mut T>

source

pub fn last_mut(&mut self) -> Option<&mut T>

source

pub fn push(&mut self, val: T)

source

pub fn pop(&mut self) -> Option<T>

source

pub fn push_slice(&mut self, data: &[T])where T: Clone,

source

pub fn extend(&mut self, data: impl IntoIterator<Item = T>)

source

pub fn clear(&mut self)

source

pub fn clone_buffer(&self) -> Selfwhere T: Clone,

Allocate a clone of this buffer.

source

pub fn clone_buffer_with_capacity(&self, cap: usize) -> Selfwhere T: Clone,

Allocate a clone of this buffer with a different capacity

The capacity must be at least as large as the buffer’s length.

source

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

Trait Implementations§

source§

impl<T> AsMut<[T]> for UniqueVector<T>

source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T> AsRef<[T]> for UniqueVector<T>

source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: Clone> Clone for UniqueVector<T>

source§

fn clone(&self) -> Self

Returns a copy 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> Default for UniqueVector<T>

source§

fn default() -> Self

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

impl<T> Drop for UniqueVector<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T, I> Index<I> for UniqueVector<T>where I: SliceIndex<[T]>,

§

type Output = <I as SliceIndex<[T]>>::Output

The returned type after indexing.
source§

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

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

impl<T, I> IndexMut<I> for UniqueVector<T>where I: SliceIndex<[T]>,

source§

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

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

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

§

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?
source§

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more
source§

impl<'a, T> IntoIterator for &'a mut UniqueVector<T>

§

type Item = &'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?
source§

fn into_iter(self) -> IterMut<'a, T>

Creates an iterator from a value. Read more
source§

impl<T: PartialEq<T>> PartialEq<&[T]> for UniqueVector<T>

source§

fn eq(&self, other: &&[T]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialEq<T>> PartialEq<UniqueVector<T>> for UniqueVector<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

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

§

impl<T> !Send for UniqueVector<T>

§

impl<T> !Sync for UniqueVector<T>

§

impl<T> Unpin for UniqueVector<T>

§

impl<T> UnwindSafe for UniqueVector<T>where T: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.