pub struct Index<T> { /* private fields */ }Expand description
A type-safe, compact handle to an element in an ElemPool.
An Index<T> is essentially a wrapper around a u32, providing a cheap,
Copy-able way to reference list elements without relying on raw pointers
or garbage collection.
§Rationale
Using a custom Index type instead of a raw usize or u32 provides
several benefits:
- Type Safety:
Index<Foo>is a different type fromIndex<Bar>. This prevents accidentally using an index from a pool ofFoos to access a pool ofBars. ThePhantomData<T>marker enforces this at compile time with zero runtime cost. - “None” State: The maximum value of
u32is reserved forIndex::NONE, creating a clear, efficient “null” or “invalid” state, similar toOption<T>but without the added size overhead.
Implementations§
Trait Implementations§
Source§impl<T> Ord for Index<T>
impl<T> Ord for Index<T>
Source§impl<T> PartialOrd for Index<T>
impl<T> PartialOrd for Index<T>
impl<T> Copy for Index<T>
impl<T> Eq for Index<T>
Auto Trait Implementations§
impl<T> Freeze for Index<T>
impl<T> RefUnwindSafe for Index<T>where
T: RefUnwindSafe,
impl<T> Send for Index<T>where
T: Send,
impl<T> Sync for Index<T>where
T: Sync,
impl<T> Unpin for Index<T>where
T: Unpin,
impl<T> UnsafeUnpin for Index<T>
impl<T> UnwindSafe for Index<T>where
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