pub struct UniqueVec<T> { /* private fields */ }Implementations§
Source§impl<T> UniqueVec<T>
impl<T> UniqueVec<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new, empty UniqueVec<T>.
The vector will not allocate until elements are pushed onto it.
Copied from Vec::new and edited.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new, empty UniqueVec<T> with at least the specified capacity.
The vector will be able to hold at least capacity elements without reallocating. This method
is allowed to allocate for more elements than capacity. If capacity is 0, the vector will not
allocate.
It is important to note that although the returned vector has the minimum capacity specified, the vector will have a zero length. For an explanation of the difference between length and capacity, see Capacity and reallocation.
If it is important to know the exact allocated capacity of a UniqueVec, always use the capacity
method after construction.
For UniqueVec<T> where T is a zero-sized type, there will be no allocation and the capacity will always be
usize::MAX.
§Panics
Panics if the new capacity exceeds isize::MAX bytes.
Copied from Vec::with_capacity and edited.
Source§impl<T> UniqueVec<T>
impl<T> UniqueVec<T>
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the vector can hold without reallocating.
Copied from Vec::capacity.
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Returns an iterator over the slice.
The iterator yields all items from start to end.
Copied from Vec::iter.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the vector, also referred to as its ‘length’.
Copied from Vec::len.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the vector contains no elements.
Copied from Vec::is_empty.
Sourcepub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> Drain<'_, T> ⓘ
pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> Drain<'_, T> ⓘ
Removes the specified range from the vector in bulk, returning all removed elements as an iterator. If the iterator is dropped before being fully consumed, it drops the remaining removed elements.
The returned iterator keeps a mutable borrow on the vector to optimize its implementation.
§Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
§Leaking
If the returned iterator goes out of scope without being dropped (due to
mem::forget, for example), the vector may have
lost and leaked elements arbitrarily, including elements outside the range.
Copied from Vec::drain.
Sourcepub fn retain<F: FnMut(&T) -> bool>(&mut self, f: F)
pub fn retain<F: FnMut(&T) -> bool>(&mut self, f: F)
Retains only the elements specified by the predicate.
In other words, remove all elements e for which 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.
Copied from Vec::retain.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the vector, removing all values.
Note that this method has no effect on the allocated capacity of the vector.
Copied from Vec::clear.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be inserted in the given Vec<T>. The
collection may reserve more space to speculatively avoid frequent reallocations. After calling reserve,
capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already
sufficient.
§Panics
Panics if the new capacity exceeds isize::MAX bytes.
Copied from Vec::reserve.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for at least additional more elements to be inserted in the given Vec<T>.
Unlike reserve, this will not deliberately over-allocate to speculatively avoid
frequent allocations. After calling reserve_exact, capacity will be greater than or equal to
self.len() + additional. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be
relied upon to be precisely minimal. Prefer reserve if future insertions are expected.
§Panics
Panics if the new capacity exceeds isize::MAX bytes.
Copied from Vec::reserve_exact.
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional more elements to be inserted in the given Vec<T>.
The collection may reserve more space to speculatively avoid frequent reallocations. After calling
try_reserve, capacity will be greater than or equal to self.len() + additional if it returns Ok(()).
Does nothing if capacity is already sufficient. This method preserves the contents even if an error occurs.
§Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Copied from Vec::try_reserve.
Sourcepub fn try_reserve_exact(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Tries to reserve the minimum capacity for at least additional elements to be inserted in the given Vec<T>.
Unlike try_reserve, this will not deliberately over-allocate to speculatively avoid
frequent allocations. After calling try_reserve_exact, capacity will be greater than or equal to
self.len() + additional if it returns Ok(()). Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be
relied upon to be precisely minimal. Prefer try_reserve if future insertions are expected.
Errors If the capacity overflows, or the allocator reports a failure, then an error is returned.
Copied from Vec::try_reserve_exact.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the vector as much as possible.
The behavior of this method depends on the allocator, which may either shrink the vector in-place or reallocate.
The resulting vector might still have some excess capacity, just as is the case for
with_capacity. See
Allocator::shrink for more details.
Copied from Vec::shrink_to_fit.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the vector with a lower bound.
The capacity will remain at least as large as both the length and the supplied value.
If the current capacity is less than the lower limit, this is a no-op.
Copied from Vec::shrink_to.
pub fn get(&self, index: usize) -> Option<&T>
Source§impl<T: Eq> UniqueVec<T>
impl<T: Eq> UniqueVec<T>
Sourcepub fn contains(&self, x: &T) -> bool
pub fn contains(&self, x: &T) -> bool
Returns true if the slice contains an element with the given value.
This operation is O(n).
Copied from Vec::contains and edited.
Sourcepub fn insert(&mut self, x: T) -> bool
pub fn insert(&mut self, x: T) -> bool
Adds a value to the vector.
Returns whether the value was newly inserted. That is:
- If the vector did not previously contain this value,
trueis returned. - If the vector already contained this value,
falseis returned, and the vector is not modified: original value is not replaced, and the value passed as argument is dropped.
Copied from HashSet::insert and edited.
Sourcepub fn replace(&mut self, x: T) -> Option<T>
pub fn replace(&mut self, x: T) -> Option<T>
Adds a value to the vector, replacing the existing value, if any, that is equal to the given one. Returns the replaced value.
Copied from HashSet::replace and edited.
Trait Implementations§
Source§impl<T> IntoIterator for UniqueVec<T>
impl<T> IntoIterator for UniqueVec<T>
Source§impl<'l, T> IntoIterator for &'l UniqueVec<T>
impl<'l, T> IntoIterator for &'l UniqueVec<T>
Source§impl<'l, T> IntoIterator for &'l mut UniqueVec<T>
impl<'l, T> IntoIterator for &'l mut UniqueVec<T>
Auto Trait Implementations§
impl<T> Freeze for UniqueVec<T>
impl<T> RefUnwindSafe for UniqueVec<T>where
Vec<T>: RefUnwindSafe,
impl<T> Send for UniqueVec<T>
impl<T> Sync for UniqueVec<T>
impl<T> Unpin for UniqueVec<T>
impl<T> UnsafeUnpin for UniqueVec<T>where
Vec<T>: UnsafeUnpin,
impl<T> UnwindSafe for UniqueVec<T>where
Vec<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more