[−][src]Struct generic_vec::GenericVec
A vector type that can be backed up by a variety of different backends including slices, arrays, and the heap.
Implementations
impl<T, S: Storage<T>> GenericVec<T, S>[src]
pub fn with_storage(storage: S) -> Self[src]
Create a new empty GenericVec with the given backend
impl<T, S: StorageWithCapacity<T>> GenericVec<T, S>[src]
pub fn with_capacity(capacity: usize) -> Self[src]
Create a new empty GenericVec with the backend with at least the given capacity
impl<T> GenericVec<T, Heap<T>>[src]
impl<'a, T> GenericVec<T, Uninit<&'a mut [MaybeUninit<T>]>>[src]
pub fn new(slice: &'a mut [MaybeUninit<T>]) -> Self[src]
Create a new empty SliceVec
impl<'a, T: Copy> GenericVec<T, Init<&'a mut [T]>>[src]
pub fn new(slice: &'a mut [T]) -> Self[src]
Create a new full InitSliceVec
impl<T, S: Storage<T>> GenericVec<T, S>[src]
pub fn into_raw_parts(self) -> (usize, S)[src]
Convert a GenericVec into a length-storage pair
pub unsafe fn from_raw_parts(len: usize, storage: S) -> Self[src]
impl<T, S: ?Sized + Storage<T>> GenericVec<T, S>[src]
pub fn as_ptr(&self) -> *const T[src]
Returns a shared raw pointer to the vector's buffer.
It's not safe to write to this pointer except for values
inside of an UnsafeCell
pub fn as_mut_ptr(&mut self) -> *mut T[src]
Returns a unique raw pointer to the vector's buffer.
pub fn len(&self) -> usize[src]
Returns the number of elements in the vector
pub fn capacity(&self) -> usize[src]
Returns the number of elements the vector can hold without reallocating or panicing.
pub fn is_empty(&self) -> bool[src]
Returns true if and only if the vector contains no elements.
pub fn is_full(&self) -> bool[src]
Returns true if and only if the vector's length is equal to it's capacity.
pub fn remaining_capacity(&self) -> usize[src]
Returns the length of the spare capacity of the GenericVec
pub unsafe fn set_len_unchecked(&mut self, len: usize)[src]
Set the length of a vector
Safety
- new_len must be less than or equal to
capacity(). - The elements at
old_len..new_lenmust be initialized.
pub fn set_len(&mut self, len: usize) where
S: StorageInit<T>, [src]
S: StorageInit<T>,
Set the length of a vector
pub fn as_slice(&self) -> &[T][src]
Extracts a slice containing the entire vector.
Equivalent to &s[..].
pub fn as_mut_slice(&mut self) -> &mut [T][src]
Extracts a mutable slice containing the entire vector.
Equivalent to &mut s[..].
pub fn storage(&self) -> &S[src]
Returns the underlying raw buffer
pub unsafe fn storage_mut(&mut self) -> &mut S[src]
pub fn spare_capacity_mut(&mut self) -> SliceVec<'_, T>[src]
Returns the remaining spare capacity of the vector as a slice
of [MaybeUninit<T>] or [T]
pub fn reserve(&mut self, additional: usize)[src]
Reserve enough space for at least additional elements
Panics
May panic or abort if it isn't possible to allocate enough space for
additional more elements
pub fn try_reserve(&mut self, additional: usize) -> Result<(), AllocError>[src]
Try to reserve enough space for at least additional elements, and returns Err(_)
if it's not possible to reserve enough space
pub fn truncate(&mut self, len: usize)[src]
Shortens the vector, keeping the first len elements and dropping the rest.
If len is greater than the vector's current length, this has no effect.
Note that this method has no effect on the allocated capacity of the vector.
pub fn grow(&mut self, additional: usize, value: T) where
T: Clone, [src]
T: Clone,
Grows the GenericVec in-place by additional elements.
This method requires T to implement Clone, in order to be able to clone
the passed value. If you need more flexibility (or want to rely on Default instead of Clone),
use GenericVec::grow_with.
pub fn grow_with<F>(&mut self, additional: usize, value: F) where
F: FnMut() -> T, [src]
F: FnMut() -> T,
Grows the GenericVec in-place by additional elements.
This method uses a closure to create new values on every push.
If you'd rather Clone a given value, use GenericVec::resize.
If you want to use the Default trait to generate values, you
can pass Default::default as the second argument.
pub fn clear(&mut self)[src]
Clears the vector, removing all values.
Note that this method has no effect on the allocated capacity of the vector.
pub fn push(&mut self, value: T) -> &mut T[src]
Appends an element to the back of a collection.
Panic
May panic or reallocate if the collection is full
pub fn insert(&mut self, index: usize, value: T) -> &mut T[src]
Inserts an element at position index within the vector, shifting all elements after it to the right.
Panics
- May panic or reallocate if the collection is full
- Panics if index > len.
pub fn pop(&mut self) -> T[src]
pub fn remove(&mut self, index: usize) -> T[src]
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.
pub fn swap_remove(&mut self, index: usize) -> T[src]
Removes an element from the vector and returns it.
The removed element is replaced by the last element of the vector.
This does not preserve ordering, but is O(1).
Panics
Panics if index is out of bounds.
pub fn try_push(&mut self, value: T) -> Result<&mut T, T>[src]
Tries to append an element to the back of a collection.
Returns the Err(value) if the collection is full
Guaranteed to not panic/abort/allocate
pub fn try_insert(&mut self, index: usize, value: T) -> Result<&mut T, T>[src]
Inserts an element at position index within the vector,
shifting all elements after it to the right.
Returns the Err(value) if the collection is full or index is out of bounds
Guaranteed to not panic/abort/allocate
pub fn try_pop(&mut self) -> Option<T>[src]
Removes the last element from a vector and returns it,
Returns None if the collection is empty
Guaranteed to not panic/abort/allocate
pub fn try_remove(&mut self, index: usize) -> Option<T>[src]
Removes and returns the element at position index within the vector,
shifting all elements after it to the left.
Returns None if collection is empty or index is out of bounds.
Guaranteed to not panic/abort/allocate
pub fn try_swap_remove(&mut self, index: usize) -> Option<T>[src]
Removes an element from the vector and returns it.
Returns None if collection is empty or index is out of bounds.
The removed element is replaced by the last element of the vector.
This does not preserve ordering, but is O(1).
Guaranteed to not panic/abort/allocate
pub unsafe fn push_unchecked(&mut self, value: T) -> &mut T[src]
pub unsafe fn insert_unchecked(&mut self, index: usize, value: T) -> &mut T[src]
Inserts an element at position index within the vector, shifting all elements after it to the right.
Safety
- the collection is must not be full
- hte index must be in bounds
pub unsafe fn pop_unchecked(&mut self) -> T[src]
pub unsafe fn remove_unchecked(&mut self, index: usize) -> T[src]
Removes and returns the element at position index within the vector, shifting all elements after it to the left.
Safety
the collection must not be empty, and index must be in bounds
pub unsafe fn swap_remove_unchecked(&mut self, index: usize) -> T[src]
Removes an element from the vector and returns it.
The removed element is replaced by the last element of the vector.
This does not preserve ordering, but is O(1).
Safety
the index must be in bounds
pub fn split_off<B>(&mut self, index: usize) -> GenericVec<T, B> where
B: StorageWithCapacity<T>, [src]
B: StorageWithCapacity<T>,
Splits the collection into two at the given index.
Returns a newly allocated vector containing the elements in the range [at, len).
After the call, the original vector will be left containing the elements [0, at)
with its previous capacity unchanged.
pub fn split_off_into<B: ?Sized>(
&mut self,
index: usize,
other: &mut GenericVec<T, B>
) where
B: Storage<T>, [src]
&mut self,
index: usize,
other: &mut GenericVec<T, B>
) where
B: Storage<T>,
Splits the collection into two at the given index.
Appends the elements from the range [at, len) to other.
After the call, the original vector will be left containing the elements [0, at)
with its previous capacity unchanged.
pub fn convert<B: StorageWithCapacity<T>>(self) -> GenericVec<T, B> where
S: Sized, [src]
S: Sized,
Convert the backing buffer type, and moves all the elements in self to the new vector
pub fn raw_drain<R>(&mut self, range: R) -> RawDrain<'_, T, S> where
R: RangeBounds<usize>, [src]
R: RangeBounds<usize>,
Creates a raw drain that can be used to remove elements in the specified range.
Usage of RawDrain is unsafe because it doesn't do any checks because is
meant to be a low level tool to implement fancier iterators, like GenericVec::drain,
GenericVec::drain_filter, or GenericVec::splice.
Panic
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
pub fn drain<R>(&mut self, range: R) -> Drain<'_, T, S>ⓘ where
R: RangeBounds<usize>, [src]
R: RangeBounds<usize>,
Creates a draining iterator that removes the specified range in the vector and yields the removed items.
When the iterator is dropped, all elements in the range are removed from the vector, even if the iterator was not fully consumed. If the iterator is not dropped (with mem::forget for example), it is unspecified how many elements are removed.
Panic
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
pub fn drain_filter<R, F>(&mut self, range: R, f: F) -> DrainFilter<'_, T, S, F>ⓘNotable traits for DrainFilter<'_, T, S, F>
impl<T, S: ?Sized, F, '_> Iterator for DrainFilter<'_, T, S, F> where
S: Storage<T>,
F: FnMut(&mut T) -> bool, type Item = T; where
R: RangeBounds<usize>,
F: FnMut(&mut T) -> bool, [src]
Notable traits for DrainFilter<'_, T, S, F>
impl<T, S: ?Sized, F, '_> Iterator for DrainFilter<'_, T, S, F> where
S: Storage<T>,
F: FnMut(&mut T) -> bool, type Item = T;R: RangeBounds<usize>,
F: FnMut(&mut T) -> bool,
Creates an iterator which uses a closure to determine if an element should be removed.
If the closure returns true, then the element is removed and yielded. If the closure returns false, the element will remain in the vector and will not be yielded by the iterator.
pub fn splice<R, I>(
&mut self,
range: R,
replace_with: I
) -> Splice<'_, T, S, I::IntoIter>ⓘ where
R: RangeBounds<usize>,
I: IntoIterator<Item = T>, [src]
&mut self,
range: R,
replace_with: I
) -> Splice<'_, T, S, I::IntoIter>ⓘ where
R: RangeBounds<usize>,
I: IntoIterator<Item = T>,
Creates a splicing iterator that replaces the specified range in the vector with the given replace_with iterator and yields the removed items. replace_with does not need to be the same length as range.
range is removed even if the iterator is not consumed until the end.
It is unspecified how many elements are removed from the vector if the Splice value is leaked.
The input iterator replace_with is only consumed when the Splice value is dropped
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&mut T) -> bool, [src]
F: FnMut(&mut T) -> bool,
Retains only the elements specified by the predicate.
In other words, remove all elements e such that f(&e) returns false. This method operates in place, visiting each element exactly once in the original order, and preserves the order of the retained elements.
pub unsafe fn extend_from_slice_unchecked(&mut self, slice: &[T])[src]
Shallow copies and appends all elements in a slice to the GenericVec.
Safety
You must not drop any of the elements in slice, and
there must be at least slice.len() remaining capacity in the vector
pub fn extend_from_slice(&mut self, slice: &[T]) where
T: Clone, [src]
T: Clone,
Clones and appends all elements in a slice to the GenericVec.
Iterates over the slice other, clones each element, and then appends
it to this GenericVec. The other vector 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).
Trait Implementations
impl<T, S: ?Sized + Storage<T>> AsMut<[T]> for GenericVec<T, S>[src]
impl<T, S: ?Sized + Storage<T>> AsRef<[T]> for GenericVec<T, S>[src]
impl<T, S: ?Sized + Storage<T>> Borrow<[T]> for GenericVec<T, S>[src]
impl<T, S: ?Sized + Storage<T>> BorrowMut<[T]> for GenericVec<T, S>[src]
pub fn borrow_mut(&mut self) -> &mut [T][src]
impl<T, S: StorageWithCapacity<T>> Clone for GenericVec<T, S> where
T: Clone, [src]
T: Clone,
pub fn clone(&self) -> Self[src]
pub fn clone_from(&mut self, source: &Self)[src]
impl<T, S: ?Sized + Storage<T>> Debug for GenericVec<T, S> where
T: Debug, [src]
T: Debug,
impl<T, S: StorageWithCapacity<T>> Default for GenericVec<T, S>[src]
impl<T, S: ?Sized + Storage<T>> Deref for GenericVec<T, S>[src]
impl<T, S: ?Sized + Storage<T>> DerefMut for GenericVec<T, S>[src]
impl<T, S: ?Sized + Storage<T>> Drop for GenericVec<T, S>[src]
impl<T, S: ?Sized + Storage<T>> Eq for GenericVec<T, S> where
T: Eq, [src]
T: Eq,
impl<T, S: ?Sized + Storage<T>> Extend<T> for GenericVec<T, S>[src]
pub fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)[src]
pub fn extend_one(&mut self, item: A)[src]
pub fn extend_reserve(&mut self, additional: usize)[src]
impl<T> From<GenericVec<T, Heap<T>>> for Vec<T>[src]
impl<V, T, S: StorageWithCapacity<T>> FromIterator<V> for GenericVec<T, S> where
Self: Extend<V>, [src]
Self: Extend<V>,
pub fn from_iter<I: IntoIterator<Item = V>>(iter: I) -> Self[src]
impl<T, S: ?Sized + Storage<T>> Hash for GenericVec<T, S> where
T: Hash, [src]
T: Hash,
pub fn hash<H: Hasher>(&self, state: &mut H)[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl<T, S: Storage<T> + ?Sized, I> Index<I> for GenericVec<T, S> where
I: SliceIndex<[T]>, [src]
I: SliceIndex<[T]>,
type Output = I::Output
The returned type after indexing.
pub fn index(&self, index: I) -> &Self::Output[src]
impl<T, S: Storage<T> + ?Sized, I> IndexMut<I> for GenericVec<T, S> where
I: SliceIndex<[T]>, [src]
I: SliceIndex<[T]>,
impl<T, S: Storage<T>> IntoIterator for GenericVec<T, S>[src]
type IntoIter = IntoIter<T, S>
Which kind of iterator are we turning this into?
type Item = T
The type of the elements being iterated over.
pub fn into_iter(self) -> Self::IntoIter[src]
impl<'a, T, S: ?Sized + Storage<T>> IntoIterator for &'a mut GenericVec<T, S>[src]
type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
type Item = &'a mut T
The type of the elements being iterated over.
pub fn into_iter(self) -> Self::IntoIter[src]
impl<'a, T, S: ?Sized + Storage<T>> IntoIterator for &'a GenericVec<T, S>[src]
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
type Item = &'a T
The type of the elements being iterated over.
pub fn into_iter(self) -> Self::IntoIter[src]
impl<T, S: ?Sized + Storage<T>> Ord for GenericVec<T, S> where
T: Ord, [src]
T: Ord,
pub fn cmp(&self, other: &Self) -> Ordering[src]
#[must_use]pub fn max(self, other: Self) -> Self1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self1.50.0[src]
impl<T, O: ?Sized + AsRef<[T]>, S: ?Sized + Storage<T>> PartialEq<O> for GenericVec<T, S> where
T: PartialEq, [src]
T: PartialEq,
impl<T, O: ?Sized + AsRef<[T]>, S: ?Sized + Storage<T>> PartialOrd<O> for GenericVec<T, S> where
T: PartialOrd, [src]
T: PartialOrd,
Auto Trait Implementations
impl<T, S: ?Sized> RefUnwindSafe for GenericVec<T, S> where
S: RefUnwindSafe,
T: RefUnwindSafe,
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S: ?Sized> Send for GenericVec<T, S> where
S: Send,
T: Send,
S: Send,
T: Send,
impl<T, S: ?Sized> Sync for GenericVec<T, S> where
S: Sync,
T: Sync,
S: Sync,
T: Sync,
impl<T, S: ?Sized> Unpin for GenericVec<T, S> where
S: Unpin,
T: Unpin,
S: Unpin,
T: Unpin,
impl<T, S: ?Sized> UnwindSafe for GenericVec<T, S> where
S: UnwindSafe,
T: UnwindSafe,
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,