pub trait PinnedVec<T> {
Show 15 methods // Required methods fn capacity(&self) -> usize; fn clear(&mut self); fn extend_from_slice(&mut self, other: &[T]) where T: Clone; fn get(&self, index: usize) -> Option<&T>; fn get_mut(&mut self, index: usize) -> Option<&mut T>; unsafe fn get_unchecked(&self, index: usize) -> &T; unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T; fn insert(&mut self, index: usize, element: T); fn is_empty(&self) -> bool; fn len(&self) -> usize; fn pop(&mut self) -> Option<T>; fn push(&mut self, value: T); fn remove(&mut self, index: usize) -> T; fn partial_eq<S>(&self, other: S) -> bool where S: AsRef<[T]>, T: PartialEq<T>; fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error> where T: Debug;
}
Expand description

A vector of elements of T which differs from the std::vec::Vec by the following feature:

  • memory location of an element already pushed to the collection never changes and remains valid unless:
    • the vector is dropped,
    • the vector is cleared, resized or truncated,
    • any element is inserted into the vector,
    • any element is removed or popped from the vector.

Or, more briefly, pushing or extending the vector does not change memory locations of already added elements, and hence, the corresponding references remain valid.

Safety

This trait can be considered as a marker trait: its methods are relevant for the useful ‘vec’-related side of the trait, rather than the pinned side. The implementing struct must guarantee that pushing or extending the vector does not cause the memory locations of already added elements to change.

Required Methods§

source

fn capacity(&self) -> usize

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

source

fn clear(&mut self)

Clears the vector, removing all values.

Note that this method has no effect on the allocated capacity of the vector.

source

fn extend_from_slice(&mut self, other: &[T])where T: Clone,

Clones and appends all elements in a slice to the Vec.

Iterates over the slice other, clones each element, and then appends it to this Vec. The other slice is traversed in-order.

Note that this function is same as extend except that it is specialized to work with slices instead. If and when Rust gets specialization this function will likely be deprecated (but still available).

source

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

Returns a reference to an element with the given index, returns None if the index is out of bounds.

source

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

Returns a mutable reference to an element with the given index, returns None if the index is out of bounds.

source

unsafe fn get_unchecked(&self, index: usize) -> &T

Returns a reference to an element or subslice, without doing bounds checking.

For a safe alternative see [get].

Safety

Calling this method with an out-of-bounds index is [undefined behavior] even if the resulting reference is not used.

source

unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T

Returns a mutable reference to an element or subslice, without doing bounds checking.

For a safe alternative see [get_mut].

Safety

Calling this method with an out-of-bounds index is [undefined behavior] even if the resulting reference is not used.

source

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

Inserts an element at position index within the vector, shifting all elements after it to the right.

Panics

Panics if index >= len.

source

fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

source

fn len(&self) -> usize

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

source

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

Removes the last element from a vector and returns it, or None if it is empty.

source

fn push(&mut self, value: T)

Appends an element to the back of a collection.

source

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

Removes and returns the element at position index within the vector, shifting all elements after it to the left.

Panics

Panics if index is out of bounds.

source

fn partial_eq<S>(&self, other: S) -> boolwhere S: AsRef<[T]>, T: PartialEq<T>,

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

source

fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>where T: Debug,

Formats the value using the given formatter.

Implementors§

source§

impl<T> PinnedVec<T> for FixedVec<T>