pub struct HandleId(/* private fields */);Expand description
Opaque handle identifier returned by registration methods.
Used with Trigger::One and HandleSet for type-safe trigger
configuration.
phase-476 W0 (issue 1667) — a handle names a SLOT and the GENERATION of that slot it was issued for. A released slot goes to the very next registration, so a bare index let a stale copy reach whatever took the slot, possibly an entity of another kind. Every executor lookup compares the generation, so a stale handle now answers “not found” instead.
The two are packed into one usize (slot in the low HANDLE_SLOT_BITS
bits, generation above), so the C and C++ APIs, which carry a handle as
size_t, change no type. The generation is 15 bits and never 0: 15 bits
keeps the packed value inside an i32, which nros-c stores some handles
in, and starting at 1 means a site that still treats the packed value as
an index fails on its FIRST use rather than on the first slot reuse.
The field is private so that every reader goes through slot
or to_raw, never through a raw .0 that would mean an
index in one place and a packed value in another.
Implementations§
Source§impl HandleId
impl HandleId
Sourcepub const fn for_owned_slot(slot: usize) -> Self
pub const fn for_owned_slot(slot: usize) -> Self
A handle for slot that carries NO generation, for an entity whose
holder is UNIQUE — an action server or client, whose owning object is
destroyed when the entry is released, so no copy can outlive it (the
soundness issue 1667 found for action releases). It resolves to whatever
is live in the slot.
Never use it for a handle that can be copied: a copy that outlives a release would reach the slot’s next occupant, which is exactly what the generation exists to stop. Every handle a registration ISSUES carries a generation of at least 1, so this spelling cannot be produced by accident.
Sourcepub const fn generation(self) -> u16
pub const fn generation(self) -> u16
The slot generation this handle was issued for.