#[repr(C)]pub struct GenericVec<T, S: ?Sized + Storage<Item = T>> { /* private fields */ }
Expand description
A vector type that can be backed up by a variety of different backends including slices, arrays, and the heap.
Implementations§
Source§impl<S: Storage> GenericVec<<S as Storage>::Item, S>
impl<S: Storage> GenericVec<<S as Storage>::Item, S>
Sourcepub fn with_storage(storage: S) -> Self
pub fn with_storage(storage: S) -> Self
Create a new empty GenericVec
with the given backend
use cl_generic_vec::{ArrayVec, uninit_array};
let vec = ArrayVec::<i32, 4>::with_storage(uninit_array());
Source§impl<S: StorageWithCapacity> GenericVec<<S as Storage>::Item, S>
impl<S: StorageWithCapacity> GenericVec<<S as Storage>::Item, S>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new empty GenericVec
with the backend with at least the given capacity
Source§impl<T, const N: usize> GenericVec<T, [MaybeUninit<T>; N]>
impl<T, const N: usize> GenericVec<T, [MaybeUninit<T>; N]>
Sourcepub fn from_array(array: [T; N]) -> Self
pub fn from_array(array: [T; N]) -> Self
Create a new full ArrayVec
Sourcepub fn into_array(self) -> [T; N]
pub fn into_array(self) -> [T; N]
Sourcepub fn try_into_array(self) -> Result<[T; N], Self>
pub fn try_into_array(self) -> Result<[T; N], Self>
Source§impl<T> GenericVec<T, Box<[MaybeUninit<T>]>>
impl<T> GenericVec<T, Box<[MaybeUninit<T>]>>
Source§impl<T, A: Allocator> GenericVec<T, Box<[MaybeUninit<T>], A>>
impl<T, A: Allocator> GenericVec<T, Box<[MaybeUninit<T>], A>>
Sourcepub fn with_alloc(alloc: A) -> Self
Available on crate features nightly
and alloc
only.
pub fn with_alloc(alloc: A) -> Self
nightly
and alloc
only.Create a new empty HeapVec
with the given allocator
Source§impl<'a, T> GenericVec<T, &'a mut [MaybeUninit<T>]>
impl<'a, T> GenericVec<T, &'a mut [MaybeUninit<T>]>
Source§impl<S: Storage> GenericVec<<S as Storage>::Item, S>
impl<S: Storage> GenericVec<<S as Storage>::Item, S>
Sourcepub fn into_raw_parts(self) -> (usize, S)
pub fn into_raw_parts(self) -> (usize, S)
Convert a GenericVec
into a length-storage pair
Sourcepub unsafe fn from_raw_parts(len: usize, storage: S) -> Self
pub unsafe fn from_raw_parts(len: usize, storage: S) -> Self
Source§impl<S: ?Sized + Storage> GenericVec<<S as Storage>::Item, S>
impl<S: ?Sized + Storage> GenericVec<<S as Storage>::Item, S>
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the vector can hold without reallocating or panicing.
Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true if and only if the vector’s length is equal to it’s capacity.
Sourcepub fn remaining_capacity(&self) -> usize
pub fn remaining_capacity(&self) -> usize
Returns the length of the spare capacity of the GenericVec
Sourcepub unsafe fn set_len_unchecked(&mut self, len: usize)
pub unsafe fn set_len_unchecked(&mut self, len: usize)
Set the length of a vector
§Safety
new_len
must be less than or equal tocapacity()
.- The elements at
old_len..new_len
must be initialized.
Sourcepub fn as_slice(&self) -> &[S::Item]
pub fn as_slice(&self) -> &[S::Item]
Extracts a slice containing the entire vector.
Equivalent to &s[..].
Sourcepub fn as_mut_slice(&mut self) -> &mut [S::Item]
pub fn as_mut_slice(&mut self) -> &mut [S::Item]
Extracts a mutable slice containing the entire vector.
Equivalent to &mut s[..].
Sourcepub unsafe fn storage_mut(&mut self) -> &mut S
pub unsafe fn storage_mut(&mut self) -> &mut S
Sourcepub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<S::Item>]
pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<S::Item>]
Returns the remaining spare capacity of the vector as
a SliceVec<'_, T>
.
Keep in mind that the SliceVec<'_, T>
will drop all elements
that you push into it when it goes out of scope! If you want
these modifications to persist then you should use save_spare
to persist these writes.
let mut vec = cl_generic_vec::ArrayVec::<i32, 16>::new();
let mut spare = vec.spare_capacity_mut();
spare.push(0);
spare.push(2);
drop(spare);
assert_eq!(vec, []);
let mut spare = vec.spare_capacity_mut();
spare.push(0);
spare.push(2);
unsafe { cl_generic_vec::save_spare!(spare, &mut vec) }
assert_eq!(vec, [0, 2]);
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
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
Sourcepub fn try_reserve(&mut self, additional: usize) -> AllocResult
pub fn try_reserve(&mut self, additional: usize) -> AllocResult
Try to reserve enough space for at least additional
elements
§Errors
Returns Err(_)
if it’s not possible to reserve enough space
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
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.
Sourcepub fn grow(&mut self, additional: usize, value: S::Item)
pub fn grow(&mut self, additional: usize, value: S::Item)
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
.
§Panic
May panic or reallocate if the collection is full
§Panic behavor
If T::clone
panics, then all added items will be dropped. This is different
from std
, where on panic, items will stay in the Vec
. This behavior
is unstable, and may change in the future.
Sourcepub fn grow_with<F>(&mut self, additional: usize, value: F)
pub fn grow_with<F>(&mut self, additional: usize, value: F)
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.
§Panic
May panic or reallocate if the collection is full
§Panic behavor
If F
panics, then all added items will be dropped. This is different
from std
, where on panic, items will stay in the Vec
. This behavior
is unstable, and may change in the future.
Sourcepub fn resize(&mut self, new_len: usize, value: S::Item)
pub fn resize(&mut self, new_len: usize, value: S::Item)
Resizes the GenericVec
in-place so that len
is equal to new_len
.
If new_len
is greater than len
, the GenericVec
is extended by the difference,
with each additional slot filled with value. If new_len
is less than len
,
the GenericVec
is simply truncated.
If you know that new_len
is larger than len
, then use GenericVec::grow
If you know that new_len
is less than len
, then use GenericVec::truncate
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::resize_with
.
§Panic
May panic or reallocate if the collection is full
§Panic behavor
If F
panics, then all added items will be dropped. This is different
from std
, where on panic, items will stay in the Vec
. This behavior
is unstable, and may change in the future.
Sourcepub fn resize_with<F: FnMut() -> S::Item>(&mut self, new_len: usize, value: F)
pub fn resize_with<F: FnMut() -> S::Item>(&mut self, new_len: usize, value: F)
Resizes the GenericVec
in-place so that len is equal to new_len
.
If new_len
is greater than len
, the GenericVec
is extended by the
difference, with each additional slot filled with the result of calling
the closure f
. The return values from f
will end up in the GenericVec
in the order they have been generated.
If new_len
is less than len
, the GenericVec
is simply truncated.
If you know that new_len
is larger than len
, then use GenericVec::grow_with
If you know that new_len
is less than len
, then use GenericVec::truncate
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.
§Panic
May panic or reallocate if the collection is full
§Panic behavor
If F
panics, then all added items will be dropped. This is different
from std
, where on panic, items will stay in the Vec
. This behavior
is unstable, and may change in the future.
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.
Sourcepub fn push(&mut self, value: S::Item) -> &mut S::Item
pub fn push(&mut self, value: S::Item) -> &mut S::Item
Appends an element to the back of a collection.
§Panic
May panic or reallocate if the collection is full
Sourcepub fn push_array<const N: usize>(
&mut self,
value: [S::Item; N],
) -> &mut [S::Item; N]
pub fn push_array<const N: usize>( &mut self, value: [S::Item; N], ) -> &mut [S::Item; N]
Appends the array to the back of a collection.
§Panic
May panic or reallocate if the collection has less than N elements remaining
Sourcepub fn insert(&mut self, index: usize, value: S::Item) -> &mut S::Item
pub fn insert(&mut self, index: usize, value: S::Item) -> &mut S::Item
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.
Sourcepub fn insert_array<const N: usize>(
&mut self,
index: usize,
value: [S::Item; N],
) -> &mut [S::Item; N]
pub fn insert_array<const N: usize>( &mut self, index: usize, value: [S::Item; N], ) -> &mut [S::Item; N]
Inserts the array at position index within the vector, shifting all elements after it to the right.
§Panics
- May panic or reallocate if the collection has less than N elements remaining
- Panics if index > len.
Sourcepub fn pop_array<const N: usize>(&mut self) -> [S::Item; N]
pub fn pop_array<const N: usize>(&mut self) -> [S::Item; N]
Removes the last N
elements from a vector and returns it
§Panics
Panics if the collection contains less than N
elements in it
Sourcepub fn remove(&mut self, index: usize) -> S::Item
pub fn remove(&mut self, index: usize) -> S::Item
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.
Sourcepub fn remove_array<const N: usize>(&mut self, index: usize) -> [S::Item; N]
pub fn remove_array<const N: usize>(&mut self, index: usize) -> [S::Item; N]
Removes and returns N
elements at position index within the vector,
shifting all elements after it to the left.
§Panics
Panics if index
is out of bounds or if index + N > len()
Sourcepub fn swap_remove(&mut self, index: usize) -> S::Item
pub fn swap_remove(&mut self, index: usize) -> S::Item
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.
Sourcepub fn try_push(&mut self, value: S::Item) -> Result<&mut S::Item, S::Item>
pub fn try_push(&mut self, value: S::Item) -> Result<&mut S::Item, S::Item>
Tries to append an element to the back of a collection.
§Errors
Returns the Err(value)
if the collection is full
Guaranteed to not panic/abort/allocate
Sourcepub fn try_push_array<const N: usize>(
&mut self,
value: [S::Item; N],
) -> Result<&mut [S::Item; N], [S::Item; N]>
pub fn try_push_array<const N: usize>( &mut self, value: [S::Item; N], ) -> Result<&mut [S::Item; N], [S::Item; N]>
Tries to append an array to the back of a collection.
Returns the Err(value)
if the collection doesn’t have enough remaining capacity
to hold N
elements.
Guaranteed to not panic/abort/allocate
Sourcepub fn try_insert(
&mut self,
index: usize,
value: S::Item,
) -> Result<&mut S::Item, S::Item>
pub fn try_insert( &mut self, index: usize, value: S::Item, ) -> Result<&mut S::Item, S::Item>
Inserts an element at position index within the vector, shifting all elements after it to the right.
§Errors
Returns the Err(value)
if the collection is full or index is out of bounds
Guaranteed to not panic/abort/allocate
Sourcepub fn try_insert_array<const N: usize>(
&mut self,
index: usize,
value: [S::Item; N],
) -> Result<&mut [S::Item; N], [S::Item; N]>
pub fn try_insert_array<const N: usize>( &mut self, index: usize, value: [S::Item; N], ) -> Result<&mut [S::Item; N], [S::Item; N]>
Inserts an array at position index within the vector,
shifting all elements after it to the right.
Returns the Err(value)
if the collection doesn’t have enough remaining capacity
to hold N
elements or index is out of bounds
Guaranteed to not panic/abort/allocate
Sourcepub fn try_pop(&mut self) -> Option<S::Item>
pub fn try_pop(&mut self) -> Option<S::Item>
Removes the last element from a vector and returns it,
Returns None
if the collection is empty
Guaranteed to not panic/abort/allocate
Sourcepub fn try_pop_array<const N: usize>(&mut self) -> Option<[S::Item; N]>
pub fn try_pop_array<const N: usize>(&mut self) -> Option<[S::Item; N]>
Removes the last N
elements from a vector and returns it,
Returns None
if the collection is has less than N elements
Guaranteed to not panic/abort/allocate
Sourcepub fn try_remove(&mut self, index: usize) -> Option<S::Item>
pub fn try_remove(&mut self, index: usize) -> Option<S::Item>
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
Sourcepub fn try_remove_array<const N: usize>(
&mut self,
index: usize,
) -> Option<[S::Item; N]>
pub fn try_remove_array<const N: usize>( &mut self, index: usize, ) -> Option<[S::Item; N]>
Removes and returns the element at position index within the vector,
shifting all elements after it to the left.
Returns None
if the collection is has less than N elements
or index
is out of bounds.
Guaranteed to not panic/abort/allocate
Sourcepub fn try_swap_remove(&mut self, index: usize) -> Option<S::Item>
pub fn try_swap_remove(&mut self, index: usize) -> Option<S::Item>
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
Sourcepub unsafe fn push_unchecked(&mut self, value: S::Item) -> &mut S::Item
pub unsafe fn push_unchecked(&mut self, value: S::Item) -> &mut S::Item
Sourcepub unsafe fn push_array_unchecked<const N: usize>(
&mut self,
value: [S::Item; N],
) -> &mut [S::Item; N]
pub unsafe fn push_array_unchecked<const N: usize>( &mut self, value: [S::Item; N], ) -> &mut [S::Item; N]
Appends the array to the back of a collection.
§Safety
the collection’s remaining capacity must be at least N
Sourcepub unsafe fn insert_unchecked(
&mut self,
index: usize,
value: S::Item,
) -> &mut S::Item
pub unsafe fn insert_unchecked( &mut self, index: usize, value: S::Item, ) -> &mut S::Item
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
- the index must be in bounds
Sourcepub unsafe fn insert_array_unchecked<const N: usize>(
&mut self,
index: usize,
value: [S::Item; N],
) -> &mut [S::Item; N]
pub unsafe fn insert_array_unchecked<const N: usize>( &mut self, index: usize, value: [S::Item; N], ) -> &mut [S::Item; N]
Inserts an array at position index within the vector, shifting all elements after it to the right.
§Safety
- the collection’s remaining capacity must be at least N
- hte index must be in bounds
Sourcepub unsafe fn pop_unchecked(&mut self) -> S::Item
pub unsafe fn pop_unchecked(&mut self) -> S::Item
Sourcepub unsafe fn pop_array_unchecked<const N: usize>(&mut self) -> [S::Item; N]
pub unsafe fn pop_array_unchecked<const N: usize>(&mut self) -> [S::Item; N]
Removes the last N
elements from a vector and returns it
§Safety
The collection must contain at least N
elements in it
Sourcepub unsafe fn remove_unchecked(&mut self, index: usize) -> S::Item
pub unsafe fn remove_unchecked(&mut self, index: usize) -> S::Item
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
Sourcepub unsafe fn remove_array_unchecked<const N: usize>(
&mut self,
index: usize,
) -> [S::Item; N]
pub unsafe fn remove_array_unchecked<const N: usize>( &mut self, index: usize, ) -> [S::Item; N]
Removes and returns the element at position index within the vector, shifting all elements after it to the left.
§Safety
the collection must contain at least N elements, and index must be in bounds
Sourcepub unsafe fn swap_remove_unchecked(&mut self, index: usize) -> S::Item
pub unsafe fn swap_remove_unchecked(&mut self, index: usize) -> S::Item
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
Sourcepub fn split_off<B>(&mut self, index: usize) -> GenericVec<S::Item, B>where
B: StorageWithCapacity<Item = S::Item>,
pub fn split_off<B>(&mut self, index: usize) -> GenericVec<S::Item, B>where
B: StorageWithCapacity<Item = S::Item>,
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.
assert_eq!(vec, [1, 2, 3]);
assert_eq!(vec2, [4, 5, 6]);
vec.split_off_into(1, &mut vec2);
assert_eq!(vec, [1]);
assert_eq!(vec2, [4, 5, 6, 2, 3]);
§Panics
If the index is out of bounds
Sourcepub fn split_off_into<B>(
&mut self,
index: usize,
other: &mut GenericVec<S::Item, B>,
)
pub fn split_off_into<B>( &mut self, index: usize, other: &mut GenericVec<S::Item, B>, )
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.
assert_eq!(vec, [1, 2, 3]);
assert_eq!(vec2, [4, 5, 6]);
vec.split_off_into(1, &mut vec2);
assert_eq!(vec, [1]);
assert_eq!(vec2, [4, 5, 6, 2, 3]);
§Panics
If the index is out of bounds
Sourcepub fn append<B: Storage<Item = S::Item> + ?Sized>(
&mut self,
other: &mut GenericVec<S::Item, B>,
)
pub fn append<B: Storage<Item = S::Item> + ?Sized>( &mut self, other: &mut GenericVec<S::Item, B>, )
Moves all the elements of other
into Self
, leaving other
empty.
Does not change the capacity of either collection.
assert_eq!(vec, [1, 2, 3]);
assert_eq!(vec2, [4, 5, 6]);
vec.append(&mut vec2);
assert_eq!(vec, [1, 2, 3, 4, 5, 6]);
assert_eq!(vec2, []);
§Panic
May panic or reallocate if the collection is full
Sourcepub fn convert<B: StorageWithCapacity<Item = S::Item>>(
self,
) -> GenericVec<S::Item, B>where
S: Sized,
pub fn convert<B: StorageWithCapacity<Item = S::Item>>(
self,
) -> GenericVec<S::Item, B>where
S: Sized,
Convert the backing storage type, and moves all the elements in self
to the new vector
Sourcepub fn raw_cursor<R>(&mut self, range: R) -> RawCursor<'_, S>where
R: RangeBounds<usize>,
pub fn raw_cursor<R>(&mut self, range: R) -> RawCursor<'_, S>where
R: RangeBounds<usize>,
Creates a raw cursor that can be used to remove elements in the specified range.
Usage of RawCursor
is unsafe
because it doesn’t do any checks.
RawCursor
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.
Sourcepub fn cursor<R>(&mut self, range: R) -> Cursor<'_, S>where
R: RangeBounds<usize>,
pub fn cursor<R>(&mut self, range: R) -> Cursor<'_, S>where
R: RangeBounds<usize>,
Creates a cursor that can be used to remove elements in the specified range.
§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.
Sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, S> ⓘwhere
R: RangeBounds<usize>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_, S> ⓘwhere
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.
Sourcepub fn drain_filter<R, F>(&mut self, range: R, f: F) -> DrainFilter<'_, S, F> ⓘ
pub fn drain_filter<R, F>(&mut self, range: R, f: F) -> DrainFilter<'_, S, F> ⓘ
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.
§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.
Sourcepub fn splice<R, I>(
&mut self,
range: R,
replace_with: I,
) -> Splice<'_, S, I::IntoIter> ⓘ
pub fn splice<R, I>( &mut self, range: R, replace_with: I, ) -> Splice<'_, S, I::IntoIter> ⓘ
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
§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.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
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.
Sourcepub unsafe fn extend_from_slice_unchecked(&mut self, slice: &[S::Item])
pub unsafe fn extend_from_slice_unchecked(&mut self, slice: &[S::Item])
Shallow copies and appends all elements in a slice to the GenericVec
.
§Safety
- You must not drop any of the elements in
slice
- There must be at least
slice.len()
remaining capacity in the vector
Sourcepub fn extend_from_slice(&mut self, slice: &[S::Item])
pub fn extend_from_slice(&mut self, slice: &[S::Item])
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).
§Panic behavor
If T::clone
panics, then all newly added items will be dropped. This is different
from std
, where on panic, newly added items will stay in the Vec
. This behavior
is unstable, and may change in the future.
Sourcepub fn clone_from(&mut self, source: &[S::Item])
pub fn clone_from(&mut self, source: &[S::Item])
Replaces all of the current elements with the ones in the slice
equivalent to the following
vec.clear();
vec.extend_from_slice(&slice);
§Panic
May try to panic/reallocate if there is not enough capacity for the slice
Sourcepub fn dedup_by<F>(&mut self, same_bucket: F)
pub fn dedup_by<F>(&mut self, same_bucket: F)
Removes all but the first of consecutive elements in the vector satisfying a given equality relation.
The same_bucket
function is passed references to two elements from the
vector and must determine if the elements compare equal. The elements
are passed in opposite order from their order in the slice, so if
same_bucket(a, b)
returns true, a is removed.
If the vector is sorted, this removes all duplicates.
Sourcepub fn dedup_by_key<F, K>(&mut self, key: F)
pub fn dedup_by_key<F, K>(&mut self, key: F)
Removes all but the first of consecutive elements in the vector that resolve to the same key.
If the vector is sorted, this removes all duplicates.