Skip to main content

UniqueVec

Struct UniqueVec 

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

Behaves like an ordered HashSet, though in reality is just a Vec.

Implementations§

Source§

impl<T> UniqueVec<T>

Source

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.

Source

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>

Source

pub fn capacity(&self) -> usize

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

Copied from Vec::capacity.

Source

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.

Source

pub fn len(&self) -> usize

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

Copied from Vec::len.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

Copied from Vec::is_empty.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

impl<T: Eq> UniqueVec<T>

Source

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.

Source

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, true is returned.
  • If the vector already contained this value, false is 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.

Source

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.

Source

pub fn remove(&mut self, x: &T) -> bool

Removes a value from the vector. Returns whether the value was present in the vector.

The value may be any borrowed form of the vector’s value type, but Eq on the borrowed form must match those for the value type.

Copied from HashSet::remove and edited.

Source

pub fn take(&mut self, x: &T) -> Option<T>

Removes and returns a value in the vector, if any, that is equal to the given one.

The value may be any borrowed form of the vector’s value type, but Eq on the borrowed form must match those for the value type.

Copied from HashSet::take and edited.

Trait Implementations§

Source§

impl<T: Clone> Clone for UniqueVec<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> IntoIterator for UniqueVec<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'l, T> IntoIterator for &'l UniqueVec<T>

Source§

type Item = &'l T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'l, T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'l, T> IntoIterator for &'l mut UniqueVec<T>

Source§

type Item = &'l mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'l, T>

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<T> Freeze for UniqueVec<T>
where Vec<T>: Freeze,

§

impl<T> RefUnwindSafe for UniqueVec<T>
where Vec<T>: RefUnwindSafe,

§

impl<T> Send for UniqueVec<T>
where Vec<T>: Send,

§

impl<T> Sync for UniqueVec<T>
where Vec<T>: Sync,

§

impl<T> Unpin for UniqueVec<T>
where Vec<T>: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.