pub struct IdxVec<I: Idx, T> {
inner: Box<[T]>,
_phantom: PhantomData<I>,
}Expand description
An immutable vector that can only be indexed by type-safe 32-bit indices.
Use IdxVec::new or IdxVec::default to create a new instance.
Fields§
§inner: Box<[T]>§_phantom: PhantomData<I>Implementations§
Source§impl<I: Idx, T> IdxVec<I, T>
impl<I: Idx, T> IdxVec<I, T>
Sourcepub fn new(elements: Vec<T>) -> Result<Self, IdxVecOverflowError>
pub fn new(elements: Vec<T>) -> Result<Self, IdxVecOverflowError>
Creates a new IdxVec with the given elements in it.
If the number of elements is larger than what can be addressed by a
u32, i.e. u32::MAX, an error is returned instead.
fn validate_index(&self, index: u32) -> Option<I>
Sourcepub unsafe fn get(&self, index: I) -> &T
pub unsafe fn get(&self, index: I) -> &T
Gets an element from this vector by its index.
§Safety
The caller must ensure that the index object was validated using the
same vector as self or a different vector used to create self
through IdxVec::map.
pub fn len(&self) -> u32
pub fn iter_enumerated(&self) -> impl Iterator<Item = (I, &T)>
Trait Implementations§
Auto Trait Implementations§
impl<I, T> Freeze for IdxVec<I, T>
impl<I, T> RefUnwindSafe for IdxVec<I, T>where
I: RefUnwindSafe,
T: RefUnwindSafe,
impl<I, T> Send for IdxVec<I, T>
impl<I, T> Sync for IdxVec<I, T>
impl<I, T> Unpin for IdxVec<I, T>where
I: Unpin,
impl<I, T> UnwindSafe for IdxVec<I, T>where
I: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more