Skip to main content

TypedVec

Struct TypedVec 

Source
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 implements IndexType
  • T: 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>

Source

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

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

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

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

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.

Source

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.

Source

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.

Source

pub unsafe fn from_raw_parts(ptr: *mut T, length: I, capacity: usize) -> Self

Creates a TypedVec from raw parts.

§Safety

Same as Vec::from_raw_parts.

Source

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.

Source

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

Converts the TypedVec into a Vec.

Source

pub fn len(&self) -> I

Returns the length of the vector as an index.

Source

pub const fn len_usize(&self) -> usize

Returns the length of the vector as a usize.

Source

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.

Source

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

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

pub fn iter_enumerated(&self) -> UncheckedTypedEnumerate<I, Iter<'_, T>>

Returns an iterator over the elements with their indices.

Source

pub fn iter_mut_enumerated( &mut self, ) -> UncheckedTypedEnumerate<I, IterMut<'_, T>>

Returns an iterator over the elements with their mutable references and indices.

Source

pub fn into_iter_enumerated(self) -> UncheckedTypedEnumerate<I, IntoIter<T>>

Consumes the vector and returns an iterator over the elements with their indices.

Source

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

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

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn as_mut_ptr(&mut self) -> *mut T

Returns a raw pointer to the vector’s buffer.

Source

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

Reserves capacity for at least additional more elements.

See Vec::reserve for details.

Source

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

Reserves the exact capacity for additional more elements.

See Vec::reserve_exact for details.

Source

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.

Source

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.

Source

pub fn shrink_to_fit(&mut self)

Reduces the capacity to fit the current length.

See Vec::shrink_to_fit for details.

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the capacity to at least the specified minimum.

See Vec::shrink_to for details.

Source

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.

Source

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.

Source

pub fn as_slice(&self) -> &TypedSlice<I, T>

Returns the vector as a typed slice reference.

Source

pub fn as_mut_slice(&mut self) -> &mut TypedSlice<I, T>

Returns a mutable typed slice reference.

Source

pub fn cast_index_type<I2: IndexType>( self, ) -> Result<TypedVec<I2, T>, I2::IndexTooBigError>

Casts the index type of the TypedVec.

Source

pub const fn as_ptr(&self) -> *const T

Returns a raw pointer to the vector’s buffer.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&T) -> bool,

Retains only elements that satisfy the predicate.

See Vec::retain for details.

Source

pub fn retain_mut<F>(&mut self, f: F)
where F: FnMut(&mut T) -> bool,

Retains only elements that satisfy the predicate, passing a mutable reference.

See Vec::retain_mut for details.

Source

pub fn dedup_by_key<F, K>(&mut self, key: F)
where F: FnMut(&mut T) -> K, K: PartialEq,

Removes consecutive duplicate elements, using key to determine equality.

See Vec::dedup_by_key for details.

Source

pub fn dedup_by<F>(&mut self, same_bucket: F)
where F: FnMut(&mut T, &mut T) -> bool,

Removes consecutive duplicate elements, using same_bucket to determine equality.

See Vec::dedup_by for details.

Source

pub fn pop(&mut self) -> Option<T>

Removes and returns the last element, or None if the vector is empty.

Source

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.

Source

pub fn clear(&mut self)

Removes all elements from the vector.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

Source

pub fn split_off(&mut self, at: I) -> Self

Splits the vector into two at the given index.

Returns everything after the split point.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source

pub fn dedup(&mut self)

Removes consecutive duplicate elements.

See Vec::dedup for details.

Source§

impl<I: IndexType, T: Clone> TypedVec<I, T>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn extract_if<F, R>(&mut self, range: R, filter: F) -> ExtractIf<'_, T, F>
where F: FnMut(&mut T) -> bool, R: RangeBounds<I>,

Creates an iterator that filters and transforms elements, removing them in place.

See Vec::extract_if for details.

Source

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

Source

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

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

Source

pub fn as_slice(&self) -> &[T]

Returns the TypedSlice as a raw slice reference.

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns the TypedSlice as a mutable raw slice reference.

Source

pub fn cast_index_type<I2: IndexType>( &self, ) -> Result<&TypedSlice<I2, T>, I2::IndexTooBigError>

Casts the index type of the TypedSlice.

Source

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.

Source

pub fn len_usize(&self) -> usize

Returns the length of the slice as a usize.

Source

pub fn len(&self) -> I

Returns the length of the slice as an index.

Source

pub fn is_empty(&self) -> bool

Returns true if the slice is empty.

Source

pub fn first(&self) -> Option<&T>

Source

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

Source

pub fn split_first(&self) -> Option<(&T, &TypedSlice<I, T>)>

Source

pub fn split_first_mut(&mut self) -> Option<(&mut T, &mut TypedSlice<I, T>)>

Source

pub fn split_last(&self) -> Option<(&T, &TypedSlice<I, T>)>

Source

pub fn split_last_mut(&mut self) -> Option<(&mut T, &mut TypedSlice<I, T>)>

Source

pub fn last(&self) -> Option<&T>

Source

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

Source

pub fn first_chunk<const N: usize>(&self) -> Option<&TypedArray<I, T, N>>

Source

pub fn first_chunk_mut<const N: usize>( &mut self, ) -> Option<&mut TypedArray<I, T, N>>

Source

pub fn split_first_chunk<const N: usize>( &self, ) -> Option<(&TypedArray<I, T, N>, &TypedSlice<I, T>)>

Source

pub fn split_first_chunk_mut<const N: usize>( &mut self, ) -> Option<(&mut TypedArray<I, T, N>, &mut TypedSlice<I, T>)>

Source

pub fn split_last_chunk<const N: usize>( &self, ) -> Option<(&TypedSlice<I, T>, &TypedArray<I, T, N>)>

Source

pub fn split_last_chunk_mut<const N: usize>( &mut self, ) -> Option<(&mut TypedSlice<I, T>, &mut TypedArray<I, T, N>)>

Source

pub fn last_chunk<const N: usize>(&self) -> Option<&TypedArray<I, T, N>>

Source

pub fn last_chunk_mut<const N: usize>( &mut self, ) -> Option<&mut TypedArray<I, T, N>>

Source

pub fn get<X>(&self, index: X) -> Option<&X::Output>
where X: TypedSliceIndex<Self>,

Source

pub fn get_mut<X>(&mut self, index: X) -> Option<&mut X::Output>
where X: TypedSliceIndex<Self>,

Source

pub unsafe fn get_unchecked<X>(&self, index: X) -> &X::Output
where X: TypedSliceIndex<Self>,

§Safety

The index must be in bounds.

Source

pub unsafe fn get_unchecked_mut<X>(&mut self, index: X) -> &mut X::Output
where X: TypedSliceIndex<Self>,

§Safety

The index must be in bounds.

Source

pub fn as_ptr(&self) -> *const T

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Source

pub fn as_ptr_range(&self) -> Range<*const T>

Source

pub fn as_mut_ptr_range(&mut self) -> Range<*mut T>

Source

pub fn as_array<const N: usize>(&self) -> Option<&TypedArray<I, T, N>>

Source

pub fn as_mut_array<const N: usize>( &mut self, ) -> Option<&mut TypedArray<I, T, N>>

Source

pub fn swap(&mut self, a: I, b: I)

Source

pub fn reverse(&mut self)

Source

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

Source

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

Source

pub fn indices(&self) -> TypedRange<I>

Returns an iterator over the valid indices of this slice.

Source

pub fn iter_enumerated(&self) -> UncheckedTypedEnumerate<I, Iter<'_, T>>

Returns an iterator over the elements with their indices.

Source

pub fn iter_mut_enumerated( &mut self, ) -> UncheckedTypedEnumerate<I, IterMut<'_, T>>

Returns an iterator over the elements with their mutable references and indices.

Source

pub unsafe fn as_chunks_unchecked<const N: usize>( &self, ) -> &TypedSlice<I, TypedArray<I, T, N>>

§Safety

See core::slice::as_chunks_unchecked.

Source

pub fn as_chunks<const N: usize>( &self, ) -> (&TypedSlice<I, TypedArray<I, T, N>>, &TypedSlice<I, T>)

Source

pub fn as_rchunks<const N: usize>( &self, ) -> (&TypedSlice<I, T>, &TypedSlice<I, TypedArray<I, T, N>>)

Source

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.

Source

pub fn as_chunks_mut<const N: usize>( &mut self, ) -> (&mut TypedSlice<I, TypedArray<I, T, N>>, &mut TypedSlice<I, T>)

Source

pub fn as_rchunks_mut<const N: usize>( &mut self, ) -> (&mut TypedSlice<I, T>, &mut TypedSlice<I, TypedArray<I, T, N>>)

Source

pub unsafe fn split_at_unchecked( &self, mid: I, ) -> (&TypedSlice<I, T>, &TypedSlice<I, T>)

§Safety

mid must be in bounds.

Source

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.

Source

pub fn split_at_checked( &self, mid: I, ) -> Option<(&TypedSlice<I, T>, &TypedSlice<I, T>)>

Source

pub fn split_at_mut_checked( &mut self, mid: I, ) -> Option<(&mut TypedSlice<I, T>, &mut TypedSlice<I, T>)>

Source

pub fn splitn<F>( &self, n: usize, pred: F, ) -> Map<SplitN<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn splitn_mut<F>( &mut self, n: usize, pred: F, ) -> Map<SplitNMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn rsplitn<F>( &self, n: usize, pred: F, ) -> Map<RSplitN<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn rsplitn_mut<F>( &mut self, n: usize, pred: F, ) -> Map<RSplitNMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn contains(&self, x: &T) -> bool
where T: PartialEq,

Source

pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<I, I>
where F: FnMut(&'a T) -> Ordering,

Source

pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<I, I>
where F: FnMut(&'a T) -> B, B: Ord,

Source

pub fn sort_unstable(&mut self)
where T: Ord,

Source

pub fn sort_unstable_by<F>(&mut self, compare: F)
where F: FnMut(&T, &T) -> Ordering,

Source

pub fn sort_unstable_by_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord,

Source

pub fn select_nth_unstable( &mut self, index: I, ) -> (&mut TypedSlice<I, T>, &mut T, &mut TypedSlice<I, T>)
where T: Ord,

Source

pub fn select_nth_unstable_by<F>( &mut self, index: I, compare: F, ) -> (&mut TypedSlice<I, T>, &mut T, &mut TypedSlice<I, T>)
where F: FnMut(&T, &T) -> Ordering,

Source

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>)
where F: FnMut(&T) -> K, K: Ord,

Source

pub fn rotate_left(&mut self, mid: I)

Source

pub fn rotate_right(&mut self, k: I)

Source

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

Source

pub fn fill_with<F>(&mut self, f: F)
where F: FnMut() -> T,

Source

pub fn copy_within<R: RangeBounds<I>>(&mut self, src: R, dest: I)
where T: Copy,

Source

pub fn is_sorted(&self) -> bool
where T: PartialOrd,

Source

pub fn is_sorted_by<'a, F>(&'a self, compare: F) -> bool
where F: FnMut(&'a T, &'a T) -> bool,

Source

pub fn is_sorted_by_key<'a, F, K>(&'a self, f: F) -> bool
where F: FnMut(&'a T) -> K, K: PartialOrd,

Source

pub fn partition_point<P>(&self, pred: P) -> I
where P: FnMut(&T) -> bool,

Source

pub fn get_disjoint_mut<X, const N: usize>( &mut self, indices: [X; N], ) -> Result<[&mut X::Output; N], GetDisjointMutError>

Source

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.

Source

pub fn windows( &self, size: usize, ) -> Map<Windows<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>

Source

pub fn chunks( &self, size: usize, ) -> Map<Chunks<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>

Source

pub fn chunks_mut( &mut self, size: usize, ) -> Map<ChunksMut<'_, T>, fn(&mut [T]) -> &mut TypedSlice<I, T>>

Source

pub fn rchunks( &self, size: usize, ) -> Map<RChunks<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>

Source

pub fn rchunks_mut( &mut self, size: usize, ) -> Map<RChunksMut<'_, T>, fn(&mut [T]) -> &mut TypedSlice<I, T>>

Source

pub fn split_at(&self, mid: I) -> (&TypedSlice<I, T>, &TypedSlice<I, T>)

Source

pub fn split_at_mut( &mut self, mid: I, ) -> (&mut TypedSlice<I, T>, &mut TypedSlice<I, T>)

Source

pub fn split<F>( &self, pred: F, ) -> Map<Split<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn split_mut<F>( &mut self, pred: F, ) -> Map<SplitMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn split_inclusive<F>( &self, pred: F, ) -> Map<SplitInclusive<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn split_inclusive_mut<F>( &mut self, pred: F, ) -> Map<SplitInclusiveMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn starts_with(&self, needle: &TypedSlice<I, T>) -> bool
where T: PartialEq,

Source

pub fn ends_with(&self, needle: &TypedSlice<I, T>) -> bool
where T: PartialEq,

Source

pub fn clone_from_slice(&mut self, src: &TypedSlice<I, T>)
where T: Clone,

Source

pub fn copy_from_slice(&mut self, src: &TypedSlice<I, T>)
where T: Copy,

Source

pub fn swap_with_slice(&mut self, other: &mut TypedSlice<I, T>)

Source

pub fn align_to<U>(&self) -> (&TypedSlice<I, T>, &[U], &TypedSlice<I, T>)

Source

pub fn align_to_mut<U>( &mut self, ) -> (&mut TypedSlice<I, T>, &mut [U], &mut TypedSlice<I, T>)

Source

pub fn chunk_by<F>( &self, pred: F, ) -> Map<ChunkBy<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
where F: FnMut(&T, &T) -> bool,

Source

pub fn chunk_by_mut<F>( &mut self, pred: F, ) -> Map<ChunkByMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
where F: FnMut(&T, &T) -> bool,

Source

pub fn chunks_exact( &self, chunk_size: usize, ) -> Map<ChunksExact<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>

Source

pub fn chunks_exact_mut( &mut self, chunk_size: usize, ) -> Map<ChunksExactMut<'_, T>, fn(&mut [T]) -> &mut TypedSlice<I, T>>

Source

pub fn rchunks_exact( &self, chunk_size: usize, ) -> Map<RChunksExact<'_, T>, fn(&[T]) -> &TypedSlice<I, T>>

Source

pub fn rchunks_exact_mut( &mut self, chunk_size: usize, ) -> Map<RChunksExactMut<'_, T>, fn(&mut [T]) -> &mut TypedSlice<I, T>>

Source

pub fn repeat(&self, n: usize) -> Result<TypedVec<I, T>, I::IndexTooBigError>
where T: Copy,

Source

pub fn rsplit_mut<F>( &mut self, pred: F, ) -> Map<RSplitMut<'_, T, F>, fn(&mut [T]) -> &mut TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn rsplit<F>( &self, pred: F, ) -> Map<RSplit<'_, T, F>, fn(&[T]) -> &TypedSlice<I, T>>
where F: FnMut(&T) -> bool,

Source

pub fn sort(&mut self)
where T: Ord,

Source

pub fn sort_by<F>(&mut self, compare: F)
where F: FnMut(&T, &T) -> Ordering,

Source

pub fn sort_by_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord,

Source

pub fn sort_by_cached_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord,

Source

pub fn split_off_first<'a>(self: &mut &'a Self) -> Option<&'a T>

Source

pub fn split_off_first_mut<'a>(self: &mut &'a mut Self) -> Option<&'a mut T>

Source

pub fn split_off_last<'a>(self: &mut &'a Self) -> Option<&'a T>

Source

pub fn split_off_last_mut<'a>(self: &mut &'a mut Self) -> Option<&'a mut T>

Source

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>

Source§

fn as_mut(&mut self) -> &mut TypedSlice<I, T>

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

impl<I: IndexType, T> AsMut<TypedVec<I, T>> for TypedVec<I, T>

Source§

fn as_mut(&mut self) -> &mut TypedVec<I, T>

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

impl<I: IndexType, T> AsRef<TypedSlice<I, T>> for TypedVec<I, T>

Source§

fn as_ref(&self) -> &TypedSlice<I, T>

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

impl<I: IndexType, T> AsRef<TypedVec<I, T>> for TypedVec<I, T>

Source§

fn as_ref(&self) -> &TypedVec<I, T>

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

impl<I: IndexType, T> Borrow<TypedSlice<I, T>> for TypedVec<I, T>

Source§

fn borrow(&self) -> &TypedSlice<I, T>

Immutably borrows from an owned value. Read more
Source§

impl<I: IndexType, T> BorrowMut<TypedSlice<I, T>> for TypedVec<I, T>

Source§

fn borrow_mut(&mut self) -> &mut TypedSlice<I, T>

Mutably borrows from an owned value. Read more
Source§

impl<I: IndexType, T: Clone> Clone for TypedVec<I, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

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

Performs copy-assignment from source. Read more
Source§

impl<I: IndexType, T: Debug> Debug for TypedVec<I, T>

Source§

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

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

impl<I: IndexType, T> Default for TypedVec<I, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<I: IndexType, T> Deref for TypedVec<I, T>

Source§

type Target = TypedSlice<I, T>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<I: IndexType, T> DerefMut for TypedVec<I, T>

Source§

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

Mutably dereferences the value.
Source§

impl<I: IndexType, T> Extend<T> for TypedVec<I, T>

Source§

fn extend<X: IntoIterator<Item = T>>(&mut self, iter: X)

Extends a collection with the contents of an iterator. Read more
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<'a, I: IndexType, T: Clone> From<&'a TypedSlice<I, T>> for TypedVec<I, T>

Source§

fn from(value: &'a TypedSlice<I, T>) -> Self

Converts to this type from the input type.
Source§

impl<I: IndexType, T> FromIterator<T> for TypedVec<I, T>

Source§

fn from_iter<X: IntoIterator<Item = T>>(iter: X) -> Self

Creates a value from an iterator. Read more
Source§

impl<I: IndexType, T: Hash> Hash for TypedVec<I, T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, I: IndexType, T> IntoIterator for &'a TypedVec<I, 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, I: IndexType, T> IntoIterator for &'a mut TypedVec<I, 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<I: IndexType, T> IntoIterator for TypedVec<I, 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<I: IndexType, T: Ord> Ord for TypedVec<I, T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<I: IndexType, T: PartialEq> PartialEq<TypedSlice<I, T>> for TypedVec<I, T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<I: IndexType, T: PartialEq> PartialEq for TypedVec<I, T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<I: IndexType, T: PartialOrd> PartialOrd for TypedVec<I, T>

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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<I: IndexType, T: Eq> Eq for TypedVec<I, T>

Auto Trait Implementations§

§

impl<I, T> Freeze for TypedVec<I, T>

§

impl<I, T> RefUnwindSafe for TypedVec<I, T>
where T: RefUnwindSafe,

§

impl<I, T> Send for TypedVec<I, T>
where T: Send,

§

impl<I, T> Sync for TypedVec<I, T>
where T: Sync,

§

impl<I, T> Unpin for TypedVec<I, T>
where T: Unpin,

§

impl<I, T> UnsafeUnpin for TypedVec<I, T>

§

impl<I, T> UnwindSafe for TypedVec<I, 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.