pub struct PopulatedVec<T>(/* private fields */);Expand description
A non-empty Vec with at least one element.
Implementations§
Source§impl<T> PopulatedVec<T>
impl<T> PopulatedVec<T>
Sourcepub fn new(value: T) -> PopulatedVec<T>
pub fn new(value: T) -> PopulatedVec<T>
Constructs a Vec<T> populated with a single element.
Sourcepub fn with_capacity(capacity: NonZeroUsize, value: T) -> PopulatedVec<T>
pub fn with_capacity(capacity: NonZeroUsize, value: T) -> PopulatedVec<T>
Creates a new PopulatedVec with the specified capacity.
The capacity must be non-zero. This creates a PopulatedVec with the specified capacity and the first element initialized
with the provided value.
Sourcepub fn pushed(vec: Vec<T>, value: T) -> PopulatedVec<T>
pub fn pushed(vec: Vec<T>, value: T) -> PopulatedVec<T>
Constructs a PopulatedVec from a Vec<T> by pushing a single element to it.
use populated::PopulatedVec;
let vec = vec![1];
let vec = PopulatedVec::pushed(vec, 2);
assert_eq!(vec.len().get(), 2);
assert_eq!(vec.first(), &1);
assert_eq!(vec.last(), &2);Sourcepub fn inserted(vec: Vec<T>, index: usize, value: T) -> PopulatedVec<T>
pub fn inserted(vec: Vec<T>, index: usize, value: T) -> PopulatedVec<T>
Constructs a PopulatedVec from a Vec<T> by inserting a single element at the specified index.
If the index is out of bounds, it will panic.
If the index is within bounds, it will insert the element at the specified index.
use populated::PopulatedVec;
let vec = vec![1, 3];
let vec = PopulatedVec::inserted(vec, 1, 2);
assert_eq!(vec.len().get(), 3);
assert_eq!(vec.first(), &1);
assert_eq!(vec.last(), &3);Sourcepub fn from_first_and_rest_array<const N: usize>(
first: T,
rest: [T; N],
) -> PopulatedVec<T>
pub fn from_first_and_rest_array<const N: usize>( first: T, rest: [T; N], ) -> PopulatedVec<T>
Constructs a PopulatedVec from a Vec<T> by providing the first element and the rest of the elements from an array.
use populated::PopulatedVec;
let vec = PopulatedVec::from_first_and_rest_array(1, [2, 3]);
assert_eq!(vec.len().get(), 3);
assert_eq!(vec.first(), &1);
assert_eq!(vec.last(), &3);Sourcepub fn into_inner(self) -> Vec<T>
pub fn into_inner(self) -> Vec<T>
Returns the underlying Vec<T>.
Sourcepub fn extend_from_array<const N: usize>(&mut self, array: [T; N])
pub fn extend_from_array<const N: usize>(&mut self, array: [T; N])
Appends elements from a slice to the back of a collection.
This is a safe operation because this is a PopulatedVec.
use populated::PopulatedVec;
let mut vec = PopulatedVec::new(1);
vec.extend_from_slice(&[2, 3]);
assert_eq!(vec.len().get(), 3);
assert_eq!(vec.last(), &3);Sourcepub fn pop(self) -> (Vec<T>, T)
pub fn pop(self) -> (Vec<T>, T)
Removes the last element from the vector and returns it, along with
the remaining vector. Note that this is a safe operation because
this is a PopulatedVec.
use populated::PopulatedVec;
let vec = PopulatedVec::new(1);
let (vec, last) = vec.pop();
assert_eq!(last, 1);
assert_eq!(vec.len(), 0);§Returns
A tuple containing Vec (with the last element removed) and the last element of the vector
The returned Vec has no additional guarantees about its length.
Sourcepub fn first(&self) -> &T
pub fn first(&self) -> &T
Returns the first element of the slice. This is a safe operation
because this is a PopulatedVec.
use populated::PopulatedVec;
let vec = PopulatedVec::new(1);
assert_eq!(vec.first(), &1);§Returns
A reference to the first element of the vector.
Sourcepub fn last(&self) -> &T
pub fn last(&self) -> &T
Returns the last element of the slice. This is a safe operation
because this is a PopulatedVec.
use populated::PopulatedVec;
let vec = PopulatedVec::new(1);
assert_eq!(vec.last(), &1);§Returns
A reference to the last element of the vector.
Sourcepub fn len(&self) -> NonZeroUsize
pub fn len(&self) -> NonZeroUsize
Returns the number of elements in the vector, also referred to as its
‘length’. It is non-zero because this is a PopulatedVec.
use populated::PopulatedVec;
let vec = PopulatedVec::new(1);
assert_eq!(vec.len().get(), 1);§Returns
The number of elements in the vector.
Sourcepub fn capacity(&self) -> NonZeroUsize
pub fn capacity(&self) -> NonZeroUsize
Returns the total number of elements the vector can hold without
reallocating. Since this is a PopulatedVec, it is guaranteed to
be non-zero.
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.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for exactly additional more elements to be inserted.
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.
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 exactly additional more elements to be inserted.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the vector as much as possible.
Sourcepub fn shrink_to(&mut self, min_capacity: NonZeroUsize)
pub fn shrink_to(&mut self, min_capacity: NonZeroUsize)
Shrinks the capacity of the vector to the minimum allowed capacity. Note that this is a safe operation because capacity is guaranteed to be non-zero.
Sourcepub fn truncate(&mut self, len: NonZeroUsize)
pub fn truncate(&mut self, len: NonZeroUsize)
Shortens the vector, keeping the first len elements and dropping the rest.
Note that this is a safe operation because length is guaranteed to be non-zero.
Sourcepub fn truncate_into(self, len: usize) -> Vec<T>
pub fn truncate_into(self, len: usize) -> Vec<T>
Shortens the vector, keeping the first len elements and dropping the rest.
The truncated Vec is returned.
use populated::PopulatedVec;
let vec = PopulatedVec::new(1);
let vec = vec.truncate_into(0);
assert_eq!(vec.len(), 0);§Returns
A new Vec with the first len elements of the original vector.
The returned Vec has no additional guarantees about its length.
Sourcepub fn as_slice(&self) -> &PopulatedSlice<T>
pub fn as_slice(&self) -> &PopulatedSlice<T>
Extracts a slice containing the entire vector.
use populated::PopulatedVec;
let vec = PopulatedVec::new(1);
let slice = vec.as_slice();
assert_eq!(slice.len().get(), 1);§Returns
A PopulatedSlice containing the entire vector. The returned PopulatedSlice guarantees that it is non-empty.
Sourcepub fn as_mut_slice(&mut self) -> &mut PopulatedSlice<T>
pub fn as_mut_slice(&mut self) -> &mut PopulatedSlice<T>
Extracts a mutable slice containing the entire vector.
use populated::PopulatedVec;
let mut vec = PopulatedVec::new(1);
let slice = vec.as_mut_slice();
assert_eq!(slice.len().get(), 1);§Returns
A mutable PopulatedSlice containing the entire vector. The returned PopulatedSlice guarantees that it is non-empty.
Sourcepub fn swap_remove(self, index: usize) -> (T, Vec<T>)
pub fn swap_remove(self, index: usize) -> (T, Vec<T>)
Removes an element from the vector and returns it along with the
remaining Vec.
The removed element is replaced by the last element of the vector.
This does not preserve ordering, but is O(1). If you need to preserve the element order, use remove instead.
§Panics
Panics if the index is out of bounds.
Sourcepub fn insert(&mut self, index: usize, element: T)
pub 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.
Sourcepub fn remove(self, index: usize) -> (T, Vec<T>)
pub fn remove(self, index: usize) -> (T, Vec<T>)
Removes and returns the element at position index within the
populated vector, shifting all elements after it to the left and
returns the resulting Vec.
Note: Because this shifts over the remaining elements, it has a
worst-case performance of O(n). If you don’t need the order of
elements to be preserved, use swap_remove instead. If you’d like
to remove elements from the beginning of the Vec, consider using
VecDeque::pop_front instead.
Sourcepub fn retain(self, f: impl FnMut(&T) -> bool) -> Vec<T>
pub fn retain(self, f: impl FnMut(&T) -> bool) -> Vec<T>
Retains only the elements specified by the predicate in the
returned Vec.
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.
Sourcepub fn retain_mut(self, f: impl FnMut(&mut T) -> bool) -> Vec<T>
pub fn retain_mut(self, f: impl FnMut(&mut T) -> bool) -> Vec<T>
Retains only the elements specified by the predicate in the returned
Vec, passing a mutable reference to it.
In other words, remove all elements e such that f(&mut 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 fn dedup_by_key<K: PartialEq>(&mut self, key: impl FnMut(&mut T) -> K)
pub fn dedup_by_key<K: PartialEq>(&mut self, key: impl FnMut(&mut T) -> K)
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.
Sourcepub fn dedup_by(&mut self, same_bucket: impl FnMut(&mut T, &mut T) -> bool)
pub fn dedup_by(&mut self, same_bucket: impl FnMut(&mut T, &mut T) -> bool)
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 append(&mut self, other: &mut Vec<T>)
pub fn append(&mut self, other: &mut Vec<T>)
Moves all the elements of other into self, leaving other empty.
pub fn split_off(&mut self, at: NonZeroUsize) -> Vec<T>
pub fn split_into(self, at: usize) -> (Vec<T>, Vec<T>)
Source§impl<T: Clone> PopulatedVec<T>
impl<T: Clone> PopulatedVec<T>
Sourcepub fn resize(&mut self, new_len: NonZeroUsize, value: T)
pub fn resize(&mut self, new_len: NonZeroUsize, value: T)
Resizes the vector in place so that len is equal to new_len.
If new_len is greater than len, the vector is extended by the
difference, with each additional slot filled with value. If new_len
is less than len, the vector is simply truncated.
Sourcepub fn resize_into(self, new_len: usize, value: T) -> Vec<T>
pub fn resize_into(self, new_len: usize, value: T) -> Vec<T>
Resizes the vector in place so that len is equal to new_len.
If new_len is greater than len, the vector is extended by the
difference, with each additional slot filled with value. If new_len
is less than len, the vector is simply truncated.
This is a safe operation because this it returns the underlying Vec that can be empty.
Sourcepub fn extend_from_slice(&mut self, other: &[T])
pub fn extend_from_slice(&mut self, other: &[T])
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).
Sourcepub fn extend_from_within(&mut self, src: impl RangeBounds<usize>)
pub fn extend_from_within(&mut self, src: impl RangeBounds<usize>)
Copies elements from src range to the end of the vector.
Source§impl<T: PartialEq> PopulatedVec<T>
impl<T: PartialEq> PopulatedVec<T>
Source§impl<T> PopulatedVec<T>
impl<T> PopulatedVec<T>
Sourcepub fn iter(&self) -> PopulatedIter<'_, T>
pub fn iter(&self) -> PopulatedIter<'_, T>
Returns a populated iterator over the elements of the vector.
Sourcepub fn iter_mut(&mut self) -> PopulatedIterMut<'_, T>
pub fn iter_mut(&mut self) -> PopulatedIterMut<'_, T>
Returns a mutable populated iterator over the elements of the vector.
Methods from Deref<Target = PopulatedSlice<T>>§
Sourcepub fn iter(&self) -> PopulatedIter<'_, T>
pub fn iter(&self) -> PopulatedIter<'_, T>
Returns a populated iterator over the slice.
Sourcepub fn iter_mut(&mut self) -> PopulatedIterMut<'_, T>
pub fn iter_mut(&mut self) -> PopulatedIterMut<'_, T>
Returns a mutable populated iterator over the slice.
Sourcepub fn len(&self) -> NonZeroUsize
pub fn len(&self) -> NonZeroUsize
Returns the length of the populated slice.
use populated::PopulatedSlice;
use std::num::NonZeroUsize;
let slice: &[u64] = &[1, 2, 3];
let slice: &PopulatedSlice<u64> = TryFrom::try_from(slice).unwrap();
assert_eq!(slice.len(), NonZeroUsize::new(3).unwrap());Sourcepub fn first_mut(&mut self) -> &mut T
pub fn first_mut(&mut self) -> &mut T
Returns a mutable pointer to the first element of the populated slice.
Sourcepub fn split_first(&self) -> (&T, &[T])
pub fn split_first(&self) -> (&T, &[T])
Returns the first and all the rest of the elements of the populated slice. Note that the returned slice can be empty. It is not a PopulatedSlice.
Sourcepub fn split_first_mut(&mut self) -> (&mut T, &mut [T])
pub fn split_first_mut(&mut self) -> (&mut T, &mut [T])
Returns the first and all the rest of the elements of the populated slice. The returned first element and the rest of the elements are mutable. Note that the returned slice can be empty. It is not a PopulatedSlice.
Sourcepub fn split_last(&self) -> (&T, &[T])
pub fn split_last(&self) -> (&T, &[T])
Returns the last and all the rest of the elements of the populated slice. Note that the returned slice can be empty. It is not a PopulatedSlice.
Sourcepub fn split_last_mut(&mut self) -> (&mut T, &mut [T])
pub fn split_last_mut(&mut self) -> (&mut T, &mut [T])
Returns the mutable last and all the rest of the elements of the populated slice as a mutable slice. Note that the returned slice can be empty. It is not a PopulatedSlice.
Sourcepub fn last_mut(&mut self) -> &mut T
pub fn last_mut(&mut self) -> &mut T
Returns a mutable reference to the last item in the populated slice.
Sourcepub fn swap(&mut self, i: usize, j: usize)
pub fn swap(&mut self, i: usize, j: usize)
Swaps two elements in the slice.
If a equals to b, it’s guaranteed that elements won’t change value.
Sourcepub fn split_at_populated(
&self,
mid: NonZeroUsize,
) -> (&PopulatedSlice<T>, &[T])
pub fn split_at_populated( &self, mid: NonZeroUsize, ) -> (&PopulatedSlice<T>, &[T])
Returns a reference to an element or subslice depending on the type of index. Since mid is a NonZeroUsize, it is guaranteed that the first slice is populated.
Sourcepub fn split_at(&self, mid: usize) -> (&[T], &[T])
pub fn split_at(&self, mid: usize) -> (&[T], &[T])
Divides one slice into two at an index.
The first will contain all indices from [0, mid) (excluding the
index mid itself) and the second will contain all indices from
[mid, len) (excluding the index len itself).
Sourcepub fn split_at_mut_populated(
&mut self,
mid: NonZeroUsize,
) -> (&mut PopulatedSlice<T>, &mut [T])
pub fn split_at_mut_populated( &mut self, mid: NonZeroUsize, ) -> (&mut PopulatedSlice<T>, &mut [T])
Returns a mutable reference to an element or subslice depending on the type of index. Since mid is a NonZeroUsize, it is guaranteed that the first slice is populated.
Sourcepub fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T])
pub fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T])
Divides one mutable slice into two at an index.
The first will contain all indices from [0, mid) (excluding the
index mid itself) and the second will contain all indices from
[mid, len) (excluding the index len itself).
Sourcepub fn binary_search_by(
&self,
f: impl FnMut(&T) -> Ordering,
) -> Result<usize, usize>
pub fn binary_search_by( &self, f: impl FnMut(&T) -> Ordering, ) -> Result<usize, usize>
Binary searches this populated slice with a comparator function.
The comparator function should return an order code that indicates
whether its argument is Less, Equal or Greater the desired target. If
the slice is not sorted or if the comparator function does not
implement an order consistent with the sort order of the underlying
slice, the returned result is unspecified and meaningless.
If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. The index is chosen deterministically, but is subject to change in future versions of Rust. If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.
See also binary_search, binary_search_by_key, and partition_point.
Sourcepub fn binary_search_by_key<K: Ord>(
&self,
key: &K,
f: impl FnMut(&T) -> K,
) -> Result<usize, usize>
pub fn binary_search_by_key<K: Ord>( &self, key: &K, f: impl FnMut(&T) -> K, ) -> Result<usize, usize>
Binary searches this populated slice with a key extraction function.
Assumes that the slice is sorted by the key, for instance with sort_by_key using the same key extraction function. If the slice is not sorted by the key, the returned result is unspecified and meaningless.
If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. The index is chosen deterministically, but is subject to change in future versions of Rust. If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.
See also binary_search, binary_search_by, and partition_point.
Sourcepub fn sort_unstable_by(&mut self, f: impl FnMut(&T, &T) -> Ordering)
pub fn sort_unstable_by(&mut self, f: impl FnMut(&T, &T) -> Ordering)
Sorts the populated slice with a comparator function, but might not preserve the order of equal elements.
This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(n * log(n)) worst-case.
The comparator function must define a total ordering for the elements in the slice. If the ordering is not total, the order of the elements is unspecified. An order is a total order if it is (for all a, b and c):
- total and antisymmetric: exactly one of a < b, a == b or a > b is true, and
- transitive, a < b and b < c implies a < c. The same must hold for both == and >.
For example, while f64 doesn’t implement Ord because NaN != NaN, we can use partial_cmp as our sort function when we know the slice doesn’t contain a NaN.
Sourcepub fn sort_unstable_by_key<K: Ord>(&mut self, f: impl FnMut(&T) -> K)
pub fn sort_unstable_by_key<K: Ord>(&mut self, f: impl FnMut(&T) -> K)
Sorts the populated slice with a key extraction function, but might not preserve the order of equal elements.
This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(m * n * log(n)) worst-case, where the key function is O(m)
pub fn select_nth_unstable_by( &mut self, index: usize, compare: impl FnMut(&T, &T) -> Ordering, ) -> (&mut [T], &mut T, &mut [T])
pub fn select_nth_unstable_by_key<K: Ord>( &mut self, index: usize, key: impl FnMut(&T) -> K, ) -> (&mut [T], &mut T, &mut [T])
Sourcepub fn rotate_left(&mut self, mid: usize)
pub fn rotate_left(&mut self, mid: usize)
Rotates the slice in-place such that the first mid elements of
the slice move to the end while the last self.len() - mid
elements move to the front. After calling rotate_left, the
element previously at index mid will become the first element in
the slice.
Sourcepub fn rotate_right(&mut self, mid: usize)
pub fn rotate_right(&mut self, mid: usize)
Rotates the slice in-place such that the first self.len() - k
elements of the slice move to the end while the last k elements
move to the front. After calling rotate_right, the element
previously at index self.len() - k will become the first
element in the slice.
Sourcepub fn fill_with(&mut self, f: impl FnMut() -> T)
pub fn fill_with(&mut self, f: impl FnMut() -> T)
Fills self with elements returned by calling a closure repeatedly.
This method uses a closure to create new values. If you’d rather
Clone a given value, use fill. If you want to use the
Default trait to generate values, you can pass
Default::default as the argument.
Sourcepub fn swap_with_slice(&mut self, other: &mut PopulatedSlice<T>)
pub fn swap_with_slice(&mut self, other: &mut PopulatedSlice<T>)
Swaps all elements in self with those in other.
The length of other must be the same as self.
pub fn partition_point(&self, f: impl FnMut(&T) -> bool) -> usize
Sourcepub fn sort_by(&mut self, compare: impl FnMut(&T, &T) -> Ordering)
pub fn sort_by(&mut self, compare: impl FnMut(&T, &T) -> Ordering)
Sorts the populated slice with a comparator function.
This sort is stable (i.e., does not reorder equal elements) and O(n * log(n)) worst-case.
The comparator function must define a total ordering for the
elements in the slice. If the ordering is not total, the order of
the elements is unspecified. An order is a total order if it is
(for all a, b and c):
- total and antisymmetric: exactly one of
a < b,a == bora > bis true, and - transitive,
a < bandb < cimpliesa < c. The same must hold for both==and>.
For example, while f64 doesn’t implement Ord because NaN != NaN,
we can use partial_cmp as our sort function when we know the
slice doesn’t contain a NaN.
Sourcepub fn sort_by_key<K: Ord>(&mut self, key: impl FnMut(&T) -> K)
pub fn sort_by_key<K: Ord>(&mut self, key: impl FnMut(&T) -> K)
Sorts the slice with a key extraction function.
This sort is stable (i.e., does not reorder equal elements) and O(m * n * log(n)) worst-case, where the key function is O(m).
For expensive key functions (e.g. functions that are not simple
property accesses or basic operations), sort_by_cached_key is
likely to be significantly faster, as it does not recompute
element keys.
When applicable, unstable sorting is preferred because it is
generally faster than stable sorting and it doesn’t allocate
auxiliary memory. See sort_unstable_by_key.
Sourcepub fn sort_by_cached_key<K: Ord>(&mut self, key: impl FnMut(&T) -> K)
pub fn sort_by_cached_key<K: Ord>(&mut self, key: impl FnMut(&T) -> K)
Sorts the slice with a key extraction function.
During sorting, the key function is called at most once per element, by using temporary storage to remember the results of key evaluation. The order of calls to the key function is unspecified and may change in future versions of the standard library.
This sort is stable (i.e., does not reorder equal elements) and O(m * n + n * log(n)) worst-case, where the key function is O(m).
For simple key functions (e.g., functions that are property accesses
or basic operations), sort_by_key is likely to be faster.
pub fn fill(&mut self, value: T)
Sourcepub fn clone_from_slice(&mut self, src: &PopulatedSlice<T>)
pub fn clone_from_slice(&mut self, src: &PopulatedSlice<T>)
Copies the elements from src into self.
The length of src must be the same as self.
Sourcepub fn to_vec(&self) -> PopulatedVec<T>
pub fn to_vec(&self) -> PopulatedVec<T>
Copies self into a new Vec.
Sourcepub fn copy_from_slice(&mut self, src: &PopulatedSlice<T>)
pub fn copy_from_slice(&mut self, src: &PopulatedSlice<T>)
Copies all elements from src into self, using a memcpy.
The length of src must be the same as self.
If T does not implement Copy, use clone_from_slice.
Sourcepub fn copy_within(&mut self, src: impl RangeBounds<usize>, dest: usize)
pub fn copy_within(&mut self, src: impl RangeBounds<usize>, dest: usize)
Copies elements from one part of the slice to another part of itself, using a memmove.
src is the range within self to copy from. dest is the starting
index of the range within self to copy to, which will have the same
length as src. The two ranges may overlap. The ends of the two ranges
must be less than or equal to self.len().
pub fn repeat(&self, n: NonZeroUsize) -> PopulatedVec<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).
Note that if you have a sorted slice, binary_search may be
faster.
Sourcepub fn starts_with(&self, needle: &[T]) -> bool
pub fn starts_with(&self, needle: &[T]) -> bool
Returns true if needle is a prefix of the slice or equal to the slice.
Sourcepub fn ends_with(&self, needle: &[T]) -> bool
pub fn ends_with(&self, needle: &[T]) -> bool
Returns true if needle is a suffix of the slice or equal to the slice.
Sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>
pub fn binary_search(&self, x: &T) -> Result<usize, usize>
Binary searches this slice for a given element. If the slice is not sorted, the returned result is unspecified and meaningless.
If the value is found then Result::Ok is returned, containing the
index of the matching element. If there are multiple matches, then
any one of the matches could be returned. The index is chosen
deterministically, but is subject to change in future versions of
Rust. If the value is not found then Result::Err is returned,
containing the index where a matching element could be inserted while
maintaining sorted order.
See also binary_search_by, binary_search_by_key, and
partition_point.
Sourcepub fn sort_unstable(&mut self)
pub fn sort_unstable(&mut self)
Sorts the slice, but might not preserve the order of equal elements.
This sort is unstable (i.e., may reorder equal elements), in-place (i.e., does not allocate), and O(n * log(n)) worst-case.
pub fn select_nth_unstable(&mut self, index: usize)
Trait Implementations§
Source§impl<T> AsMut<PopulatedSlice<T>> for PopulatedVec<T>
impl<T> AsMut<PopulatedSlice<T>> for PopulatedVec<T>
Source§fn as_mut(&mut self) -> &mut PopulatedSlice<T>
fn as_mut(&mut self) -> &mut PopulatedSlice<T>
Source§impl<T> AsRef<PopulatedSlice<T>> for PopulatedVec<T>
impl<T> AsRef<PopulatedSlice<T>> for PopulatedVec<T>
Source§fn as_ref(&self) -> &PopulatedSlice<T>
fn as_ref(&self) -> &PopulatedSlice<T>
Source§impl<T> Borrow<PopulatedSlice<T>> for PopulatedVec<T>
impl<T> Borrow<PopulatedSlice<T>> for PopulatedVec<T>
Source§fn borrow(&self) -> &PopulatedSlice<T>
fn borrow(&self) -> &PopulatedSlice<T>
Source§impl<T> BorrowMut<PopulatedSlice<T>> for PopulatedVec<T>
impl<T> BorrowMut<PopulatedSlice<T>> for PopulatedVec<T>
Source§fn borrow_mut(&mut self) -> &mut PopulatedSlice<T>
fn borrow_mut(&mut self) -> &mut PopulatedSlice<T>
Source§impl<T: Clone> Clone for PopulatedVec<T>
impl<T: Clone> Clone for PopulatedVec<T>
Source§fn clone(&self) -> PopulatedVec<T>
fn clone(&self) -> PopulatedVec<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for PopulatedVec<T>
impl<T: Debug> Debug for PopulatedVec<T>
Source§impl<T> Deref for PopulatedVec<T>
impl<T> Deref for PopulatedVec<T>
Source§impl<T> DerefMut for PopulatedVec<T>
impl<T> DerefMut for PopulatedVec<T>
Source§impl<T> Extend<T> for PopulatedVec<T>
impl<T> Extend<T> for PopulatedVec<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends the vector with the contents of an iterator.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T: Clone> From<&PopulatedSlice<T>> for PopulatedVec<T>
impl<T: Clone> From<&PopulatedSlice<T>> for PopulatedVec<T>
Source§fn from(value: &PopulatedSlice<T>) -> Self
fn from(value: &PopulatedSlice<T>) -> Self
Source§impl<T: Clone> From<&mut PopulatedSlice<T>> for PopulatedVec<T>
impl<T: Clone> From<&mut PopulatedSlice<T>> for PopulatedVec<T>
Source§fn from(value: &mut PopulatedSlice<T>) -> Self
fn from(value: &mut PopulatedSlice<T>) -> Self
Source§impl<T> From<PopulatedBinaryHeap<T>> for PopulatedVec<T>
impl<T> From<PopulatedBinaryHeap<T>> for PopulatedVec<T>
Source§fn from(populated_binary_heap: PopulatedBinaryHeap<T>) -> PopulatedVec<T>
fn from(populated_binary_heap: PopulatedBinaryHeap<T>) -> PopulatedVec<T>
Source§impl<T: Ord> From<PopulatedVec<T>> for PopulatedBinaryHeap<T>
impl<T: Ord> From<PopulatedVec<T>> for PopulatedBinaryHeap<T>
Source§fn from(populated_vec: PopulatedVec<T>) -> PopulatedBinaryHeap<T>
fn from(populated_vec: PopulatedVec<T>) -> PopulatedBinaryHeap<T>
Source§impl<T> From<PopulatedVec<T>> for PopulatedVecDeque<T>
impl<T> From<PopulatedVec<T>> for PopulatedVecDeque<T>
Source§fn from(populated_vec: PopulatedVec<T>) -> PopulatedVecDeque<T>
fn from(populated_vec: PopulatedVec<T>) -> PopulatedVecDeque<T>
Source§impl<T> From<PopulatedVec<T>> for Vec<T>
impl<T> From<PopulatedVec<T>> for Vec<T>
Source§fn from(populated_vec: PopulatedVec<T>) -> Vec<T>
fn from(populated_vec: PopulatedVec<T>) -> Vec<T>
Source§impl<T> FromPopulatedIterator<T> for PopulatedVec<T>
impl<T> FromPopulatedIterator<T> for PopulatedVec<T>
Source§fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = T>) -> Self
fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = T>) -> Self
PopulatedIterator into Self.Source§impl<T> Index<RangeFull> for PopulatedVec<T>
impl<T> Index<RangeFull> for PopulatedVec<T>
Source§impl<T> Index<usize> for PopulatedVec<T>
impl<T> Index<usize> for PopulatedVec<T>
Source§impl<T> IndexMut<RangeFull> for PopulatedVec<T>
impl<T> IndexMut<RangeFull> for PopulatedVec<T>
Source§impl<T> IndexMut<usize> for PopulatedVec<T>
impl<T> IndexMut<usize> for PopulatedVec<T>
Source§impl<'a, T> IntoIterator for &'a PopulatedVec<T>
impl<'a, T> IntoIterator for &'a PopulatedVec<T>
Source§impl<'a, T> IntoIterator for &'a mut PopulatedVec<T>
impl<'a, T> IntoIterator for &'a mut PopulatedVec<T>
Source§impl<T> IntoIterator for PopulatedVec<T>
impl<T> IntoIterator for PopulatedVec<T>
Source§impl<'a, T> IntoPopulatedIterator for &'a PopulatedVec<T>
impl<'a, T> IntoPopulatedIterator for &'a PopulatedVec<T>
type PopulatedIntoIter = PopulatedIter<'a, T>
Source§fn into_populated_iter(self) -> PopulatedIter<'a, T>
fn into_populated_iter(self) -> PopulatedIter<'a, T>
PopulatedIterator.Source§impl<'a, T> IntoPopulatedIterator for &'a mut PopulatedVec<T>
impl<'a, T> IntoPopulatedIterator for &'a mut PopulatedVec<T>
type PopulatedIntoIter = PopulatedIterMut<'a, T>
Source§fn into_populated_iter(self) -> PopulatedIterMut<'a, T>
fn into_populated_iter(self) -> PopulatedIterMut<'a, T>
PopulatedIterator.Source§impl<T> IntoPopulatedIterator for PopulatedVec<T>
impl<T> IntoPopulatedIterator for PopulatedVec<T>
type PopulatedIntoIter = PopulatedIntoIter<T>
Source§fn into_populated_iter(self) -> PopulatedIntoIter<T>
fn into_populated_iter(self) -> PopulatedIntoIter<T>
PopulatedIterator.Source§impl<T: Ord> Ord for PopulatedVec<T>
impl<T: Ord> Ord for PopulatedVec<T>
Source§fn cmp(&self, other: &PopulatedVec<T>) -> Ordering
fn cmp(&self, other: &PopulatedVec<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq> PartialEq for PopulatedVec<T>
impl<T: PartialEq> PartialEq for PopulatedVec<T>
Source§impl<T: PartialOrd> PartialOrd for PopulatedVec<T>
impl<T: PartialOrd> PartialOrd for PopulatedVec<T>
Source§impl<T> TryFrom<Vec<T>> for PopulatedVec<T>
impl<T> TryFrom<Vec<T>> for PopulatedVec<T>
Source§fn try_from(vec: Vec<T>) -> Result<PopulatedVec<T>, Self::Error>
fn try_from(vec: Vec<T>) -> Result<PopulatedVec<T>, Self::Error>
Attempts to create a PopulatedVec from a Vec. If the Vec is empty, it returns the original Vec as an error.
Otherwise, it returns a PopulatedVec with Ok.
use populated::PopulatedVec;
let vec = vec![1];
let vec = PopulatedVec::try_from(vec).unwrap();
assert_eq!(vec.len().get(), 1);
assert_eq!(vec.first(), &1);If the Vec is empty, it returns the original Vec as an error.
use populated::PopulatedVec;
let vec: Vec<u64> = vec![];
let vec = PopulatedVec::try_from(vec);
assert_eq!(vec, Err(vec![]));