pub struct NodeId {
pub index: u32,
pub generation: u32,
}Expand description
A typed, generational index into the arena.
Combines an index with a generation counter to prevent use-after-free bugs
and ABA problems. When a slot is reused, its generation is incremented,
invalidating all old NodeIds pointing to that slot.
§Example
use aether_core::arena::{Arena, NodeId};
let mut arena: Arena<i32> = Arena::with_capacity(10);
let id1 = arena.insert(42).unwrap();
arena.remove(id1);
let id2 = arena.insert(99).unwrap();
// Same slot, different generation
assert_eq!(id1.index, id2.index);
assert_ne!(id1.generation, id2.generation);
// Old ID is invalid
assert!(arena.get(id1).is_none());
// New ID is valid
assert_eq!(*arena.get(id2).unwrap(), 99);§Safety
The generation counter prevents:
- Use-after-free: Old IDs become invalid when slots are reused
- ABA problem: Can’t confuse old and new values in the same slot
- Dangling references: Stale IDs return
Noneinstead of wrong data
Fields§
§index: u32§generation: u32Implementations§
Trait Implementations§
impl Copy for NodeId
impl Eq for NodeId
impl StructuralPartialEq for NodeId
Auto Trait Implementations§
impl Freeze for NodeId
impl RefUnwindSafe for NodeId
impl Send for NodeId
impl Sync for NodeId
impl Unpin for NodeId
impl UnsafeUnpin for NodeId
impl UnwindSafe for NodeId
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more