PopulatedVec

Struct PopulatedVec 

Source
pub struct PopulatedVec<T>(/* private fields */);
Expand description

A non-empty Vec with at least one element.

Implementations§

Source§

impl<T> PopulatedVec<T>

Source

pub fn new(value: T) -> PopulatedVec<T>

Constructs a Vec<T> populated with a single element.

Source

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.

Source

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);
Source

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);
Source

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);
Source

pub fn into_inner(self) -> Vec<T>

Returns the underlying Vec<T>.

Source

pub fn push(&mut self, value: T)

Appends an element to the back of a collection.

Source

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);
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted.

Source

pub fn reserve_exact(&mut self, additional: usize)

Reserves the minimum capacity for exactly additional more elements to be inserted.

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Tries to reserve capacity for at least additional more elements to be inserted.

Source

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.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the vector as much as possible.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn append(&mut self, other: &mut Vec<T>)

Moves all the elements of other into self, leaving other empty.

Source

pub fn clear(self) -> Vec<T>

Unpopulates the vector, returning the underlying Vec.

Source

pub fn split_off(&mut self, at: NonZeroUsize) -> Vec<T>

Source

pub fn split_into(self, at: usize) -> (Vec<T>, Vec<T>)

Source§

impl<T: Clone> PopulatedVec<T>

Source

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.

Source

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.

Source

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).

Source

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>

Source

pub fn dedup(&mut self)

Removes consecutive repeated elements in the vector according to the PartialEq trait implementation.

If the vector is sorted, this removes all duplicates.

Source§

impl<T> PopulatedVec<T>

Source

pub fn iter(&self) -> PopulatedIter<'_, T>

Returns a populated iterator over the elements of the vector.

Source

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

Source

pub fn iter(&self) -> PopulatedIter<'_, T>

Returns a populated iterator over the slice.

Source

pub fn iter_mut(&mut self) -> PopulatedIterMut<'_, T>

Returns a mutable populated iterator over the slice.

Source

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());
Source

pub fn first(&self) -> &T

Returns the first element of the populated slice.

Source

pub fn first_mut(&mut self) -> &mut T

Returns a mutable pointer to the first element of the populated slice.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn last(&self) -> &T

Returns the last element of the populated slice.

Source

pub fn last_mut(&mut self) -> &mut T

Returns a mutable reference to the last item in the populated slice.

Source

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.

Source

pub fn reverse(&mut self)

Reverses the order of elements in the slice, in place.

Source

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.

Source

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).

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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)

Source

pub fn select_nth_unstable_by( &mut self, index: usize, compare: impl FnMut(&T, &T) -> Ordering, ) -> (&mut [T], &mut T, &mut [T])

Source

pub fn select_nth_unstable_by_key<K: Ord>( &mut self, index: usize, key: impl FnMut(&T) -> K, ) -> (&mut [T], &mut T, &mut [T])

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn partition_point(&self, f: impl FnMut(&T) -> bool) -> usize

Source

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 == 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.

Source

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.

Source

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.

Source

pub fn fill(&mut self, value: T)

Source

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.

Source

pub fn to_vec(&self) -> PopulatedVec<T>

Copies self into a new Vec.

Source

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.

Source

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().

Source

pub fn repeat(&self, n: NonZeroUsize) -> PopulatedVec<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).

Note that if you have a sorted slice, binary_search may be faster.

Source

pub fn starts_with(&self, needle: &[T]) -> bool

Returns true if needle is a prefix of the slice or equal to the slice.

Source

pub fn ends_with(&self, needle: &[T]) -> bool

Returns true if needle is a suffix of the slice or equal to the slice.

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.

Source

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.

Source

pub fn select_nth_unstable(&mut self, index: usize)

Source

pub fn sort(&mut self)

Sorts the slice.

This sort is stable (i.e., does not reorder equal elements) and $O(n * log(n))$ worst-case.

When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn’t allocate auxiliary memory. See sort_unstable.

Trait Implementations§

Source§

impl<T> AsMut<PopulatedSlice<T>> for PopulatedVec<T>

Source§

fn as_mut(&mut self) -> &mut PopulatedSlice<T>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T> AsRef<PopulatedSlice<T>> for PopulatedVec<T>

Source§

fn as_ref(&self) -> &PopulatedSlice<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Borrow<PopulatedSlice<T>> for PopulatedVec<T>

Source§

fn borrow(&self) -> &PopulatedSlice<T>

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<PopulatedSlice<T>> for PopulatedVec<T>

Source§

fn borrow_mut(&mut self) -> &mut PopulatedSlice<T>

Mutably borrows from an owned value. Read more
Source§

impl<T: Clone> Clone for PopulatedVec<T>

Source§

fn clone(&self) -> PopulatedVec<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for PopulatedVec<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for PopulatedVec<T>

Source§

type Target = PopulatedSlice<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for PopulatedVec<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T> Extend<T> for PopulatedVec<T>

Source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T: Clone> From<&PopulatedSlice<T>> for PopulatedVec<T>

Source§

fn from(value: &PopulatedSlice<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone> From<&mut PopulatedSlice<T>> for PopulatedVec<T>

Source§

fn from(value: &mut PopulatedSlice<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<PopulatedBinaryHeap<T>> for PopulatedVec<T>

Source§

fn from(populated_binary_heap: PopulatedBinaryHeap<T>) -> PopulatedVec<T>

Converts to this type from the input type.
Source§

impl<T: Ord> From<PopulatedVec<T>> for PopulatedBinaryHeap<T>

Source§

fn from(populated_vec: PopulatedVec<T>) -> PopulatedBinaryHeap<T>

Converts to this type from the input type.
Source§

impl<T> From<PopulatedVec<T>> for PopulatedVecDeque<T>

Source§

fn from(populated_vec: PopulatedVec<T>) -> PopulatedVecDeque<T>

Converts to this type from the input type.
Source§

impl<T> From<PopulatedVec<T>> for Vec<T>

Source§

fn from(populated_vec: PopulatedVec<T>) -> Vec<T>

Converts to this type from the input type.
Source§

impl<T> FromPopulatedIterator<T> for PopulatedVec<T>

Source§

fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = T>) -> Self

Converts a PopulatedIterator into Self.
Source§

impl<T> Index<NonZero<usize>> for PopulatedVec<T>

Source§

fn index(&self, index: NonZeroUsize) -> &Self::Output

Performs the indexing (container[index]) operation for a non-zero index.

Source§

type Output = T

The returned type after indexing.
Source§

impl<T> Index<RangeFull> for PopulatedVec<T>

Source§

fn index(&self, _: RangeFull) -> &Self::Output

Performs the indexing (container[..]) operation to get a slice of the complete vector.

Source§

type Output = PopulatedSlice<T>

The returned type after indexing.
Source§

impl<T> Index<usize> for PopulatedVec<T>

Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation.

Source§

type Output = T

The returned type after indexing.
Source§

impl<T> IndexMut<RangeFull> for PopulatedVec<T>

Source§

fn index_mut(&mut self, _: RangeFull) -> &mut Self::Output

Performs the mutable indexing (container[..]) operation to get a mutable reference to get a slice of the complete vector.

Source§

impl<T> IndexMut<usize> for PopulatedVec<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation.

Source§

impl<'a, T> IntoIterator for &'a PopulatedVec<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, 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<'a, T> IntoIterator for &'a mut PopulatedVec<T>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, 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<T> IntoIterator for PopulatedVec<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<'a, T> IntoPopulatedIterator for &'a PopulatedVec<T>

Source§

type PopulatedIntoIter = PopulatedIter<'a, T>

Source§

fn into_populated_iter(self) -> PopulatedIter<'a, T>

Converts the type into a PopulatedIterator.
Source§

impl<'a, T> IntoPopulatedIterator for &'a mut PopulatedVec<T>

Source§

type PopulatedIntoIter = PopulatedIterMut<'a, T>

Source§

fn into_populated_iter(self) -> PopulatedIterMut<'a, T>

Converts the type into a PopulatedIterator.
Source§

impl<T> IntoPopulatedIterator for PopulatedVec<T>

Source§

type PopulatedIntoIter = PopulatedIntoIter<T>

Source§

fn into_populated_iter(self) -> PopulatedIntoIter<T>

Converts the type into a PopulatedIterator.
Source§

impl<T: Ord> Ord for PopulatedVec<T>

Source§

fn cmp(&self, other: &PopulatedVec<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for PopulatedVec<T>

Source§

fn eq(&self, other: &PopulatedVec<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for PopulatedVec<T>

Source§

fn partial_cmp(&self, other: &PopulatedVec<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> TryFrom<Vec<T>> for PopulatedVec<T>

Source§

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![]));
Source§

type Error = Vec<T>

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

impl<T: Eq> Eq for PopulatedVec<T>

Source§

impl<T> StructuralPartialEq for PopulatedVec<T>

Auto Trait Implementations§

§

impl<T> Freeze for PopulatedVec<T>

§

impl<T> RefUnwindSafe for PopulatedVec<T>
where T: RefUnwindSafe,

§

impl<T> Send for PopulatedVec<T>
where T: Send,

§

impl<T> Sync for PopulatedVec<T>
where T: Sync,

§

impl<T> Unpin for PopulatedVec<T>
where T: Unpin,

§

impl<T> UnwindSafe for PopulatedVec<T>
where 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.