pub struct TypedVec<I: IndexType, T> { /* private fields */ }Expand description
A growable vector with typed indexing.
TypedVec<I, T> is a wrapper around Vec<T> that uses the custom index type I
for all indexing operations. This provides compile-time guarantees that indices
cannot be accidentally used with the wrong collection.
§Type Parameters
I: The index type that implementsIndexTypeT: The element type stored in the vector
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct RowId(u32);
let mut rows: TypedVec<RowId, String> = TypedVec::new();
let id0 = rows.push("Row 0".to_string());
let id1 = rows.push("Row 1".to_string());
assert_eq!(rows[id0], "Row 0");Implementations§
Source§impl<I: IndexType, T> TypedVec<I, T>
impl<I: IndexType, T> TypedVec<I, T>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new, empty TypedVec.
The vector will not allocate until elements are pushed.
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Idx(u32);
let vec: TypedVec<Idx, i32> = TypedVec::new();
assert!(vec.is_empty());Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new TypedVec with the specified capacity.
The vector will be able to hold at least capacity elements without reallocating.
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Idx(u32);
let vec: TypedVec<Idx, i32> = TypedVec::with_capacity(10);
assert!(vec.capacity() >= 10);Sourcepub fn try_from_vec(vec: Vec<T>) -> Result<Self, I::IndexTooBigError>
pub fn try_from_vec(vec: Vec<T>) -> Result<Self, I::IndexTooBigError>
Attempts to create a TypedVec from a Vec.
Returns an error if the Vec’s length exceeds I::MAX_RAW_INDEX.
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Idx(u8);
let std_vec: Vec<i32> = vec![1, 2, 3];
let typed: Result<TypedVec<Idx, i32>, _> = TypedVec::try_from_vec(std_vec);
assert!(typed.is_ok());Sourcepub fn from_vec(vec: Vec<T>) -> Self
pub fn from_vec(vec: Vec<T>) -> Self
Creates a TypedVec from a Vec.
§Panics
Panics if the Vec’s length exceeds I::MAX_RAW_INDEX.
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Idx(u32);
let std_vec = vec![1, 2, 3];
let typed: TypedVec<Idx, i32> = TypedVec::from_vec(std_vec);
assert_eq!(typed.len().to_raw_index(), 3);Sourcepub unsafe fn from_vec_unchecked(vec: Vec<T>) -> Self
pub unsafe fn from_vec_unchecked(vec: Vec<T>) -> Self
Creates a TypedVec from a Vec without checking bounds.
§Safety
The Vec’s length must not exceed I::MAX_RAW_INDEX.
Sourcepub unsafe fn try_from_raw_parts(
ptr: *mut T,
length: usize,
capacity: usize,
) -> Result<Self, I::IndexTooBigError>
pub unsafe fn try_from_raw_parts( ptr: *mut T, length: usize, capacity: usize, ) -> Result<Self, I::IndexTooBigError>
Attempts to create a TypedVec from raw parts.
§Safety
Same as Vec::from_raw_parts, plus the length must not exceed I::MAX_RAW_INDEX.
Sourcepub unsafe fn from_raw_parts_unchecked(
ptr: *mut T,
length: usize,
capacity: usize,
) -> Self
pub unsafe fn from_raw_parts_unchecked( ptr: *mut T, length: usize, capacity: usize, ) -> Self
Creates a TypedVec from raw parts without checking bounds.
§Safety
Same as Vec::from_raw_parts, plus the length must not exceed I::MAX_RAW_INDEX.
Sourcepub unsafe fn from_raw_parts(ptr: *mut T, length: I, capacity: usize) -> Self
pub unsafe fn from_raw_parts(ptr: *mut T, length: I, capacity: usize) -> Self
Sourcepub fn into_raw_parts(self) -> (*mut T, usize, usize)
pub fn into_raw_parts(self) -> (*mut T, usize, usize)
Decomposes the TypedVec into its raw parts.
Returns the pointer, length, and capacity of the underlying Vec.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total capacity of the vector (in elements).
Note: This returns the raw usize capacity, not the typed capacity.
§Design Decision
Unlike len() which returns a typed index I, this method returns a raw
usize. This is an intentional design choice: TypedVec may have a capacity that exceeds
what the index type I can represent.
If we limited capacity to I::MAX_RAW_INDEX, strange behaviors would occur. For example,
with a u8 index type (max 255), consider this scenario:
- Vector starts with capacity 100
- After some pushes, it reallocates and doubles to capacity 200
- The next push (201st element) would require reallocation to capacity 400, which exceeds
u8::MAX_RAW_INDEX(255), so this push would fail
This would be surprising: a vector with a u8 index could suddenly fail to push even though
it should be able to hold up to 255 elements. By allowing capacity to exceed the index
type’s range, we ensure that the vector can always grow to accommodate up to 255 elements,
even if it temporarily has excess capacity.
Use len() when you need the typed length, and remaining_capacity
when you need to know how many more elements can be added before reaching the index limit.
Sourcepub fn remaining_capacity(&self) -> I
pub fn remaining_capacity(&self) -> I
Returns the remaining capacity until the vector would exceed the index type’s limit.
This is the maximum number of additional elements that can be pushed before the index type’s maximum would be exceeded, regardless of the underlying allocation.
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Idx(u8);
let vec: TypedVec<Idx, i32> = TypedVec::with_capacity(10);
// remaining_capacity is based on index type, not allocation
assert_eq!(vec.remaining_capacity().to_raw_index(), 255);Sourcepub fn indices(&self) -> TypedRange<I> ⓘ
pub fn indices(&self) -> TypedRange<I> ⓘ
Returns an iterator over the valid indices of this vector.
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Idx(u32);
let vec: TypedVec<Idx, i32> = TypedVec::from_vec(vec![10, 20, 30]);
for idx in vec.indices() {
println!("{}: {}", idx.to_raw_index(), vec[idx]);
}Sourcepub fn iter_enumerated(&self) -> UncheckedTypedEnumerate<I, Iter<'_, T>> ⓘ
pub fn iter_enumerated(&self) -> UncheckedTypedEnumerate<I, Iter<'_, T>> ⓘ
Returns an iterator over the elements with their indices.
Sourcepub fn iter_mut_enumerated(
&mut self,
) -> UncheckedTypedEnumerate<I, IterMut<'_, T>> ⓘ
pub fn iter_mut_enumerated( &mut self, ) -> UncheckedTypedEnumerate<I, IterMut<'_, T>> ⓘ
Returns an iterator over the elements with their mutable references and indices.
Sourcepub fn into_iter_enumerated(self) -> UncheckedTypedEnumerate<I, IntoIter<T>> ⓘ
pub fn into_iter_enumerated(self) -> UncheckedTypedEnumerate<I, IntoIter<T>> ⓘ
Consumes the vector and returns an iterator over the elements with their indices.
Sourcepub fn try_push(&mut self, value: T) -> Result<I, I::IndexTooBigError>
pub fn try_push(&mut self, value: T) -> Result<I, I::IndexTooBigError>
Attempts to append an element to the back of the vector.
Returns the index of the appended element, or an error if the length
would exceed I::MAX_RAW_INDEX.
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Idx(u32);
let mut vec: TypedVec<Idx, i32> = TypedVec::new();
let idx = vec.try_push(42).unwrap();
assert_eq!(vec[idx], 42);Sourcepub fn try_push_mut(&mut self, value: T) -> Result<&mut T, I::IndexTooBigError>
pub fn try_push_mut(&mut self, value: T) -> Result<&mut T, I::IndexTooBigError>
Attempts to append an element to the back of the vector.
Returns a mutable reference to the appended element, or an error if the length
would exceed I::MAX_RAW_INDEX.
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Idx(u32);
let mut vec: TypedVec<Idx, i32> = TypedVec::new();
let item = vec.try_push_mut(42).unwrap();
assert_eq!(*item, 42);Sourcepub fn push_mut(&mut self, value: T) -> &mut T
pub fn push_mut(&mut self, value: T) -> &mut T
Appends an element to the back of the vector.
Returns a mutable reference to the appended element.
§Panics
Panics if the length would exceed I::MAX_RAW_INDEX.
Sourcepub fn push(&mut self, value: T) -> I
pub fn push(&mut self, value: T) -> I
Appends an element to the back of the vector.
Returns the index of the appended element.
§Panics
Panics if the length would exceed I::MAX_RAW_INDEX.
Sourcepub fn try_append(
&mut self,
other: &mut TypedVec<I, T>,
) -> Result<(), I::IndexTooBigError>
pub fn try_append( &mut self, other: &mut TypedVec<I, T>, ) -> Result<(), I::IndexTooBigError>
Attempts to append all elements from another TypedVec to this one.
Returns an error if the combined length would exceed I::MAX_RAW_INDEX.
The source vector is emptied after the operation.
Sourcepub fn append(&mut self, other: &mut TypedVec<I, T>)
pub fn append(&mut self, other: &mut TypedVec<I, T>)
Appends all elements from another TypedVec to this one.
The source vector is emptied after the operation.
§Panics
Panics if the combined length would exceed I::MAX_RAW_INDEX.
Sourcepub const fn as_mut_ptr(&mut self) -> *mut T
pub const fn as_mut_ptr(&mut self) -> *mut T
Returns a raw pointer to the vector’s buffer.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements.
See Vec::reserve for details.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the exact capacity for additional more elements.
See Vec::reserve_exact for details.
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Attempts to reserve capacity for at least additional more elements.
See Vec::try_reserve for details.
Sourcepub fn try_reserve_exact(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Attempts to reserve the exact capacity for additional more elements.
See Vec::try_reserve_exact for details.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Reduces the capacity to fit the current length.
See Vec::shrink_to_fit for details.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity to at least the specified minimum.
See Vec::shrink_to for details.
Sourcepub fn into_boxed_slice(self) -> Box<TypedSlice<I, T>>
pub fn into_boxed_slice(self) -> Box<TypedSlice<I, T>>
Converts the vector into a boxed slice.
The resulting slice has the same lifetime as the original vector.
Sourcepub fn truncate(&mut self, len: I)
pub fn truncate(&mut self, len: I)
Shortens the vector to the specified length.
If len is greater than the current length, this has no effect.
Sourcepub fn as_slice(&self) -> &TypedSlice<I, T>
pub fn as_slice(&self) -> &TypedSlice<I, T>
Returns the vector as a typed slice reference.
Sourcepub fn as_mut_slice(&mut self) -> &mut TypedSlice<I, T>
pub fn as_mut_slice(&mut self) -> &mut TypedSlice<I, T>
Returns a mutable typed slice reference.
Sourcepub fn cast_index_type<I2: IndexType>(
self,
) -> Result<TypedVec<I2, T>, I2::IndexTooBigError>
pub fn cast_index_type<I2: IndexType>( self, ) -> Result<TypedVec<I2, T>, I2::IndexTooBigError>
Casts the index type of the TypedVec.
Sourcepub unsafe fn set_len(&mut self, new_len: I)
pub unsafe fn set_len(&mut self, new_len: I)
Sets the length of the vector.
§Safety
Same as Vec::set_len, plus the new length must not exceed I::MAX_RAW_INDEX.
Sourcepub fn swap_remove(&mut self, index: I) -> T
pub fn swap_remove(&mut self, index: I) -> T
Removes and returns the element at index, swapping the last element into that position.
This operation is O(1).
§Panics
Panics if index is out of bounds.
Sourcepub fn try_insert(
&mut self,
index: I,
element: T,
) -> Result<(), I::IndexTooBigError>
pub fn try_insert( &mut self, index: I, element: T, ) -> Result<(), I::IndexTooBigError>
Attempts to insert an element at index, shifting all elements after it to the right.
Returns an error if the new length would exceed I::MAX_RAW_INDEX.
§Panics
Panics if index > len.
Sourcepub fn try_insert_mut(
&mut self,
index: I,
element: T,
) -> Result<&mut T, I::IndexTooBigError>
pub fn try_insert_mut( &mut self, index: I, element: T, ) -> Result<&mut T, I::IndexTooBigError>
Attempts to insert an element at index, shifting all elements after it to the right.
Returns a mutable reference to the inserted element, or an error if the new length
would exceed I::MAX_RAW_INDEX.
§Panics
Panics if index > len.
Sourcepub fn insert_mut(&mut self, index: I, element: T) -> &mut T
pub fn insert_mut(&mut self, index: I, element: T) -> &mut T
Inserts an element at index, shifting all elements after it to the right.
Returns a mutable reference to the inserted element.
§Panics
Panics if index > len or if the new length would exceed I::MAX_RAW_INDEX.
Sourcepub fn insert(&mut self, index: I, element: T)
pub fn insert(&mut self, index: I, element: T)
Inserts an element at index, shifting all elements after it to the right.
§Panics
Panics if index > len or if the new length would exceed I::MAX_RAW_INDEX.
Sourcepub fn remove(&mut self, index: I) -> T
pub fn remove(&mut self, index: I) -> T
Removes and returns the element at index, shifting all elements after it to the left.
This operation is O(n).
§Panics
Panics if index is out of bounds.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only elements that satisfy the predicate.
See Vec::retain for details.
Sourcepub fn retain_mut<F>(&mut self, f: F)
pub fn retain_mut<F>(&mut self, f: F)
Retains only elements that satisfy the predicate, passing a mutable reference.
See Vec::retain_mut for details.
Sourcepub fn dedup_by_key<F, K>(&mut self, key: F)
pub fn dedup_by_key<F, K>(&mut self, key: F)
Removes consecutive duplicate elements, using key to determine equality.
See Vec::dedup_by_key for details.
Sourcepub fn dedup_by<F>(&mut self, same_bucket: F)
pub fn dedup_by<F>(&mut self, same_bucket: F)
Removes consecutive duplicate elements, using same_bucket to determine equality.
See Vec::dedup_by for details.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes and returns the last element, or None if the vector is empty.
Sourcepub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T>
pub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T>
Removes and returns the last element if predicate returns true.
See Vec::pop_if for details.
Sourcepub fn split_off(&mut self, at: I) -> Self
pub fn split_off(&mut self, at: I) -> Self
Splits the vector into two at the given index.
Returns everything after the split point.
Sourcepub fn resize_with<F>(&mut self, new_len: I, f: F)where
F: FnMut() -> T,
pub fn resize_with<F>(&mut self, new_len: I, f: F)where
F: FnMut() -> T,
Grows the vector in place, filling new positions with the result of f.
See Vec::resize_with for details.
Sourcepub fn leak<'a>(self) -> &'a mut TypedSlice<I, T>
pub fn leak<'a>(self) -> &'a mut TypedSlice<I, T>
Leaks the vector and returns a mutable reference to its contents.
See Vec::leak for details.
Sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, T>where
R: RangeBounds<I>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_, T>where
R: RangeBounds<I>,
Creates a draining iterator that removes the specified range.
See Vec::drain for details.
Sourcepub fn splice<R, X>(
&mut self,
range: R,
replace_with: X,
) -> Splice<'_, BoundedSpliceIter<I, X::IntoIter>>where
R: RangeBounds<I>,
X: IntoIterator<Item = T>,
pub fn splice<R, X>(
&mut self,
range: R,
replace_with: X,
) -> Splice<'_, BoundedSpliceIter<I, X::IntoIter>>where
R: RangeBounds<I>,
X: IntoIterator<Item = T>,
Creates a splicing iterator that removes the specified range and replaces it.
See Vec::splice for details.
Sourcepub fn try_extend<X: IntoIterator<Item = T>>(
&mut self,
iter: X,
) -> Result<(), I::IndexTooBigError>
pub fn try_extend<X: IntoIterator<Item = T>>( &mut self, iter: X, ) -> Result<(), I::IndexTooBigError>
Attempts to extend the vector with the contents of an iterator.
Returns an error if the new length would exceed I::MAX_RAW_INDEX.
On error, the vector is unchanged.
Source§impl<I: IndexType, T: PartialEq> TypedVec<I, T>
impl<I: IndexType, T: PartialEq> TypedVec<I, T>
Sourcepub fn dedup(&mut self)
pub fn dedup(&mut self)
Removes consecutive duplicate elements.
See Vec::dedup for details.
Source§impl<I: IndexType, T: Clone> TypedVec<I, T>
impl<I: IndexType, T: Clone> TypedVec<I, T>
Sourcepub fn extend_from_slice(&mut self, other: &TypedSlice<I, T>)
pub fn extend_from_slice(&mut self, other: &TypedSlice<I, T>)
Extends the vector by cloning elements from a typed slice.
See Vec::extend_from_slice for details.
Sourcepub fn try_extend_from_slice(
&mut self,
other: &TypedSlice<I, T>,
) -> Result<(), I::IndexTooBigError>
pub fn try_extend_from_slice( &mut self, other: &TypedSlice<I, T>, ) -> Result<(), I::IndexTooBigError>
Attempts to extend the vector by cloning elements from a typed slice.
Returns an error if the resulting length would exceed I::MAX_RAW_INDEX.
Sourcepub fn try_extend_from_within<R>(
&mut self,
src: R,
) -> Result<(), I::IndexTooBigError>where
R: RangeBounds<I>,
pub fn try_extend_from_within<R>(
&mut self,
src: R,
) -> Result<(), I::IndexTooBigError>where
R: RangeBounds<I>,
Attempts to copy elements from the specified range to the end of the vector.
Returns an error if the resulting length would exceed I::MAX_RAW_INDEX.
See Vec::extend_from_within for details.
Sourcepub fn extend_from_within<R>(&mut self, src: R)where
R: RangeBounds<I>,
pub fn extend_from_within<R>(&mut self, src: R)where
R: RangeBounds<I>,
Copies elements from the specified range to the end of the vector.
See Vec::extend_from_within for details.
Sourcepub fn extract_if<F, R>(&mut self, range: R, filter: F) -> ExtractIf<'_, T, F>
pub fn extract_if<F, R>(&mut self, range: R, filter: F) -> ExtractIf<'_, T, F>
Creates an iterator that filters and transforms elements, removing them in place.
See Vec::extract_if for details.
Sourcepub fn resize(&mut self, new_len: I, value: T)
pub fn resize(&mut self, new_len: I, value: T)
Resizes the vector to the specified length, filling new positions with value.
See Vec::resize for details.
Source§impl<I: IndexType, T, const N: usize> TypedVec<I, [T; N]>
impl<I: IndexType, T, const N: usize> TypedVec<I, [T; N]>
Sourcepub fn try_into_flattened(self) -> Result<TypedVec<I, T>, I::IndexTooBigError>
pub fn try_into_flattened(self) -> Result<TypedVec<I, T>, I::IndexTooBigError>
Attempts to flatten the vector of arrays into a vector of elements.
Returns an error if the flattened length would exceed I::MAX_RAW_INDEX.
§Example
use index_type::IndexType;
use index_type::vec::TypedVec;
#[derive(IndexType, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Idx(u16);
let vec: TypedVec<Idx, [u8; 2]> = TypedVec::from_vec(vec![[1, 2], [3, 4]]);
let flat: TypedVec<Idx, u8> = vec.try_into_flattened().unwrap();
assert_eq!(flat.len_usize(), 4);Sourcepub fn into_flattened(self) -> TypedVec<I, T>
pub fn into_flattened(self) -> TypedVec<I, T>
Flattens the vector of arrays into a vector of elements.
§Panics
Panics if the flattened length would exceed I::MAX_RAW_INDEX.
Methods from Deref<Target = TypedSlice<I, T>>§
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns the TypedSlice as a mutable raw slice reference.
Sourcepub fn cast_index_type<I2: IndexType>(
&self,
) -> Result<&TypedSlice<I2, T>, I2::IndexTooBigError>
pub fn cast_index_type<I2: IndexType>( &self, ) -> Result<&TypedSlice<I2, T>, I2::IndexTooBigError>
Casts the index type of the TypedSlice.
Sourcepub fn cast_index_type_mut<I2: IndexType>(
&mut self,
) -> Result<&mut TypedSlice<I2, T>, I2::IndexTooBigError>
pub fn cast_index_type_mut<I2: IndexType>( &mut self, ) -> Result<&mut TypedSlice<I2, T>, I2::IndexTooBigError>
Casts the index type of the mutable TypedSlice.
pub fn first(&self) -> Option<&T>
pub fn first_mut(&mut self) -> Option<&mut T>
pub fn split_first(&self) -> Option<(&T, &TypedSlice<I, T>)>
pub fn split_first_mut(&mut self) -> Option<(&mut T, &mut TypedSlice<I, T>)>
pub fn split_last(&self) -> Option<(&T, &TypedSlice<I, T>)>
pub fn split_last_mut(&mut self) -> Option<(&mut T, &mut TypedSlice<I, T>)>
pub fn last(&self) -> Option<&T>
pub fn last_mut(&mut self) -> Option<&mut T>
pub fn first_chunk<const N: usize>(&self) -> Option<&TypedArray<I, T, N>>
pub fn first_chunk_mut<const N: usize>( &mut self, ) -> Option<&mut TypedArray<I, T, N>>
pub fn split_first_chunk<const N: usize>( &self, ) -> Option<(&TypedArray<I, T, N>, &TypedSlice<I, T>)>
pub fn split_first_chunk_mut<const N: usize>( &mut self, ) -> Option<(&mut TypedArray<I, T, N>, &mut TypedSlice<I, T>)>
pub fn split_last_chunk<const N: usize>( &self, ) -> Option<(&TypedSlice<I, T>, &TypedArray<I, T, N>)>
pub fn split_last_chunk_mut<const N: usize>( &mut self, ) -> Option<(&mut TypedSlice<I, T>, &mut TypedArray<I, T, N>)>
pub fn last_chunk<const N: usize>(&self) -> Option<&TypedArray<I, T, N>>
pub fn last_chunk_mut<const N: usize>( &mut self, ) -> Option<&mut TypedArray<I, T, N>>
pub fn get<X>(&self, index: X) -> Option<&X::Output>where
X: TypedSliceIndex<Self>,
pub fn get_mut<X>(&mut self, index: X) -> Option<&mut X::Output>where
X: TypedSliceIndex<Self>,
Sourcepub unsafe fn get_unchecked<X>(&self, index: X) -> &X::Outputwhere
X: TypedSliceIndex<Self>,
pub unsafe fn get_unchecked<X>(&self, index: X) -> &X::Outputwhere
X: TypedSliceIndex<Self>,
§Safety
The index must be in bounds.
Sourcepub unsafe fn get_unchecked_mut<X>(&mut self, index: X) -> &mut X::Outputwhere
X: TypedSliceIndex<Self>,
pub unsafe fn get_unchecked_mut<X>(&mut self, index: X) -> &mut X::Outputwhere
X: TypedSliceIndex<Self>,
§Safety
The index must be in bounds.
pub fn as_ptr(&self) -> *const T
pub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_ptr_range(&self) -> Range<*const T>
pub fn as_mut_ptr_range(&mut self) -> Range<*mut T>
pub fn as_array<const N: usize>(&self) -> Option<&TypedArray<I, T, N>>
pub fn as_mut_array<const N: usize>( &mut self, ) -> Option<&mut TypedArray<I, T, N>>
pub fn swap(&mut self, a: I, b: I)
pub fn reverse(&mut self)
pub fn iter(&self) -> Iter<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Sourcepub fn indices(&self) -> TypedRange<I> ⓘ
pub fn indices(&self) -> TypedRange<I> ⓘ
Returns an iterator over the valid indices of this slice.
Sourcepub fn iter_enumerated(&self) -> UncheckedTypedEnumerate<I, Iter<'_, T>> ⓘ
pub fn iter_enumerated(&self) -> UncheckedTypedEnumerate<I, Iter<'_, T>> ⓘ
Returns an iterator over the elements with their indices.
Sourcepub fn iter_mut_enumerated(
&mut self,
) -> UncheckedTypedEnumerate<I, IterMut<'_, T>> ⓘ
pub fn iter_mut_enumerated( &mut self, ) -> UncheckedTypedEnumerate<I, IterMut<'_, T>> ⓘ
Returns an iterator over the elements with their mutable references and indices.
Sourcepub unsafe fn as_chunks_unchecked<const N: usize>(
&self,
) -> &TypedSlice<I, TypedArray<I, T, N>>
pub unsafe fn as_chunks_unchecked<const N: usize>( &self, ) -> &TypedSlice<I, TypedArray<I, T, N>>
§Safety
See core::slice::as_chunks_unchecked.
pub fn as_chunks<const N: usize>( &self, ) -> (&TypedSlice<I, TypedArray<I, T, N>>, &TypedSlice<I, T>)
pub fn as_rchunks<const N: usize>( &self, ) -> (&TypedSlice<I, T>, &TypedSlice<I, TypedArray<I, T, N>>)
Sourcepub unsafe fn as_chunks_unchecked_mut<const N: usize>(
&mut self,
) -> &mut TypedSlice<I, TypedArray<I, T, N>>
pub unsafe fn as_chunks_unchecked_mut<const N: usize>( &mut self, ) -> &mut TypedSlice<I, TypedArray<I, T, N>>
§Safety
See core::slice::as_chunks_unchecked_mut.
pub fn as_chunks_mut<const N: usize>( &mut self, ) -> (&mut TypedSlice<I, TypedArray<I, T, N>>, &mut TypedSlice<I, T>)
pub fn as_rchunks_mut<const N: usize>( &mut self, ) -> (&mut TypedSlice<I, T>, &mut TypedSlice<I, TypedArray<I, T, N>>)
Sourcepub unsafe fn split_at_unchecked(
&self,
mid: I,
) -> (&TypedSlice<I, T>, &TypedSlice<I, T>)
pub unsafe fn split_at_unchecked( &self, mid: I, ) -> (&TypedSlice<I, T>, &TypedSlice<I, T>)
§Safety
mid must be in bounds.
Sourcepub unsafe fn split_at_mut_unchecked(
&mut self,
mid: I,
) -> (&mut TypedSlice<I, T>, &mut TypedSlice<I, T>)
pub unsafe fn split_at_mut_unchecked( &mut self, mid: I, ) -> (&mut TypedSlice<I, T>, &mut TypedSlice<I, T>)
§Safety
mid must be in bounds.
pub fn split_at_checked( &self, mid: I, ) -> Option<(&TypedSlice<I, T>, &TypedSlice<I, T>)>
pub fn split_at_mut_checked( &mut self, mid: I, ) -> Option<(&mut TypedSlice<I, T>, &mut TypedSlice<I, T>)>
pub fn splitn<F>( &self, n: usize, pred: F, ) -> Map<SplitN<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn splitn_mut<F>( &mut self, n: usize, pred: F, ) -> Map<SplitNMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn rsplitn<F>( &self, n: usize, pred: F, ) -> Map<RSplitN<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn rsplitn_mut<F>( &mut self, n: usize, pred: F, ) -> Map<RSplitNMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn contains(&self, x: &T) -> boolwhere
T: PartialEq,
pub fn binary_search(&self, x: &T) -> Result<I, I>where
T: Ord,
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<I, I>
pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<I, I>
pub fn sort_unstable(&mut self)where
T: Ord,
pub fn sort_unstable_by<F>(&mut self, compare: F)
pub fn sort_unstable_by_key<K, F>(&mut self, f: F)
pub fn select_nth_unstable(
&mut self,
index: I,
) -> (&mut TypedSlice<I, T>, &mut T, &mut TypedSlice<I, T>)where
T: Ord,
pub fn select_nth_unstable_by<F>( &mut self, index: I, compare: F, ) -> (&mut TypedSlice<I, T>, &mut T, &mut TypedSlice<I, T>)
pub fn select_nth_unstable_by_key<K, F>( &mut self, index: I, f: F, ) -> (&mut TypedSlice<I, T>, &mut T, &mut TypedSlice<I, T>)
pub fn rotate_left(&mut self, mid: I)
pub fn rotate_right(&mut self, k: I)
pub fn fill(&mut self, value: T)where
T: Clone,
pub fn fill_with<F>(&mut self, f: F)where
F: FnMut() -> T,
pub fn copy_within<R: RangeBounds<I>>(&mut self, src: R, dest: I)where
T: Copy,
pub fn is_sorted(&self) -> boolwhere
T: PartialOrd,
pub fn is_sorted_by<'a, F>(&'a self, compare: F) -> bool
pub fn is_sorted_by_key<'a, F, K>(&'a self, f: F) -> bool
pub fn partition_point<P>(&self, pred: P) -> I
pub fn get_disjoint_mut<X, const N: usize>(
&mut self,
indices: [X; N],
) -> Result<[&mut X::Output; N], GetDisjointMutError>where
X: GetDisjointMutTypedIndex + TypedSliceIndex<Self>,
Sourcepub unsafe fn get_disjoint_unchecked_mut<X, const N: usize>(
&mut self,
indices: [X; N],
) -> [&mut X::Output; N]where
X: TypedSliceIndex<Self>,
pub unsafe fn get_disjoint_unchecked_mut<X, const N: usize>(
&mut self,
indices: [X; N],
) -> [&mut X::Output; N]where
X: TypedSliceIndex<Self>,
§Safety
All indices must be in bounds and non-overlapping.
pub fn windows( &self, size: usize, ) -> Map<Windows<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn chunks( &self, size: usize, ) -> Map<Chunks<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn chunks_mut( &mut self, size: usize, ) -> Map<ChunksMut<'_, T>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn rchunks( &self, size: usize, ) -> Map<RChunks<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn rchunks_mut( &mut self, size: usize, ) -> Map<RChunksMut<'_, T>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn split_at(&self, mid: I) -> (&TypedSlice<I, T>, &TypedSlice<I, T>)
pub fn split_at_mut( &mut self, mid: I, ) -> (&mut TypedSlice<I, T>, &mut TypedSlice<I, T>)
pub fn split<F>( &self, pred: F, ) -> Map<Split<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn split_mut<F>( &mut self, pred: F, ) -> Map<SplitMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn split_inclusive<F>( &self, pred: F, ) -> Map<SplitInclusive<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn split_inclusive_mut<F>( &mut self, pred: F, ) -> Map<SplitInclusiveMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn starts_with(&self, needle: &TypedSlice<I, T>) -> boolwhere
T: PartialEq,
pub fn ends_with(&self, needle: &TypedSlice<I, T>) -> boolwhere
T: PartialEq,
pub fn clone_from_slice(&mut self, src: &TypedSlice<I, T>)where
T: Clone,
pub fn copy_from_slice(&mut self, src: &TypedSlice<I, T>)where
T: Copy,
pub fn swap_with_slice(&mut self, other: &mut TypedSlice<I, T>)
pub fn align_to<U>(&self) -> (&TypedSlice<I, T>, &[U], &TypedSlice<I, T>)
pub fn align_to_mut<U>( &mut self, ) -> (&mut TypedSlice<I, T>, &mut [U], &mut TypedSlice<I, T>)
pub fn chunk_by<F>( &self, pred: F, ) -> Map<ChunkBy<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn chunk_by_mut<F>( &mut self, pred: F, ) -> Map<ChunkByMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn chunks_exact( &self, chunk_size: usize, ) -> Map<ChunksExact<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn chunks_exact_mut( &mut self, chunk_size: usize, ) -> Map<ChunksExactMut<'_, T>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn rchunks_exact( &self, chunk_size: usize, ) -> Map<RChunksExact<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn rchunks_exact_mut( &mut self, chunk_size: usize, ) -> Map<RChunksExactMut<'_, T>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn repeat(&self, n: usize) -> Result<TypedVec<I, T>, I::IndexTooBigError>where
T: Copy,
pub fn rsplit_mut<F>( &mut self, pred: F, ) -> Map<RSplitMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
pub fn rsplit<F>( &self, pred: F, ) -> Map<RSplit<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
pub fn sort(&mut self)where
T: Ord,
pub fn sort_by<F>(&mut self, compare: F)
pub fn sort_by_key<K, F>(&mut self, f: F)
pub fn sort_by_cached_key<K, F>(&mut self, f: F)
pub fn split_off_first<'a>(self: &mut &'a Self) -> Option<&'a T>
pub fn split_off_first_mut<'a>(self: &mut &'a mut Self) -> Option<&'a mut T>
pub fn split_off_last<'a>(self: &mut &'a Self) -> Option<&'a T>
pub fn split_off_last_mut<'a>(self: &mut &'a mut Self) -> Option<&'a mut T>
pub fn to_vec(&self) -> TypedVec<I, T>where
T: Clone,
Trait Implementations§
Source§impl<I: IndexType, T> AsMut<TypedSlice<I, T>> for TypedVec<I, T>
impl<I: IndexType, T> AsMut<TypedSlice<I, T>> for TypedVec<I, T>
Source§fn as_mut(&mut self) -> &mut TypedSlice<I, T>
fn as_mut(&mut self) -> &mut TypedSlice<I, T>
Source§impl<I: IndexType, T> AsRef<TypedSlice<I, T>> for TypedVec<I, T>
impl<I: IndexType, T> AsRef<TypedSlice<I, T>> for TypedVec<I, T>
Source§fn as_ref(&self) -> &TypedSlice<I, T>
fn as_ref(&self) -> &TypedSlice<I, T>
Source§impl<I: IndexType, T> Borrow<TypedSlice<I, T>> for TypedVec<I, T>
impl<I: IndexType, T> Borrow<TypedSlice<I, T>> for TypedVec<I, T>
Source§fn borrow(&self) -> &TypedSlice<I, T>
fn borrow(&self) -> &TypedSlice<I, T>
Source§impl<I: IndexType, T> BorrowMut<TypedSlice<I, T>> for TypedVec<I, T>
impl<I: IndexType, T> BorrowMut<TypedSlice<I, T>> for TypedVec<I, T>
Source§fn borrow_mut(&mut self) -> &mut TypedSlice<I, T>
fn borrow_mut(&mut self) -> &mut TypedSlice<I, T>
Source§impl<I: IndexType, T> Extend<T> for TypedVec<I, T>
impl<I: IndexType, T> Extend<T> for TypedVec<I, T>
Source§fn extend<X: IntoIterator<Item = T>>(&mut self, iter: X)
fn extend<X: IntoIterator<Item = T>>(&mut self, iter: X)
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<'a, I: IndexType, T: Clone> From<&'a TypedSlice<I, T>> for TypedVec<I, T>
impl<'a, I: IndexType, T: Clone> From<&'a TypedSlice<I, T>> for TypedVec<I, T>
Source§fn from(value: &'a TypedSlice<I, T>) -> Self
fn from(value: &'a TypedSlice<I, T>) -> Self
Source§impl<I: IndexType, T> FromIterator<T> for TypedVec<I, T>
impl<I: IndexType, T> FromIterator<T> for TypedVec<I, T>
Source§fn from_iter<X: IntoIterator<Item = T>>(iter: X) -> Self
fn from_iter<X: IntoIterator<Item = T>>(iter: X) -> Self
Source§impl<'a, I: IndexType, T> IntoIterator for &'a TypedVec<I, T>
impl<'a, I: IndexType, T> IntoIterator for &'a TypedVec<I, T>
Source§impl<'a, I: IndexType, T> IntoIterator for &'a mut TypedVec<I, T>
impl<'a, I: IndexType, T> IntoIterator for &'a mut TypedVec<I, T>
Source§impl<I: IndexType, T> IntoIterator for TypedVec<I, T>
impl<I: IndexType, T> IntoIterator for TypedVec<I, T>
Source§impl<I: IndexType, T: Ord> Ord for TypedVec<I, T>
impl<I: IndexType, T: Ord> Ord for TypedVec<I, T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a, I: IndexType, T: PartialEq> PartialEq<&'a TypedSlice<I, T>> for TypedVec<I, T>
impl<'a, I: IndexType, T: PartialEq> PartialEq<&'a TypedSlice<I, T>> for TypedVec<I, T>
Source§fn eq(&self, other: &&'a TypedSlice<I, T>) -> bool
fn eq(&self, other: &&'a TypedSlice<I, T>) -> bool
self and other values to be equal, and is used by ==.Source§impl<'a, I: IndexType, T: PartialEq> PartialEq<&'a mut TypedSlice<I, T>> for TypedVec<I, T>
impl<'a, I: IndexType, T: PartialEq> PartialEq<&'a mut TypedSlice<I, T>> for TypedVec<I, T>
Source§fn eq(&self, other: &&'a mut TypedSlice<I, T>) -> bool
fn eq(&self, other: &&'a mut TypedSlice<I, T>) -> bool
self and other values to be equal, and is used by ==.Source§impl<I: IndexType, T: PartialEq> PartialEq<TypedSlice<I, T>> for TypedVec<I, T>
impl<I: IndexType, T: PartialEq> PartialEq<TypedSlice<I, T>> for TypedVec<I, T>
Source§fn eq(&self, other: &TypedSlice<I, T>) -> bool
fn eq(&self, other: &TypedSlice<I, T>) -> bool
self and other values to be equal, and is used by ==.