Skip to main content

HandleId

Struct HandleId 

Source
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

Source

pub const fn for_owned_slot(slot: usize) -> HandleId

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.

Source

pub const fn slot(self) -> usize

The entry slot this handle names.

Source

pub const fn generation(self) -> u16

The slot generation this handle was issued for.

Source

pub const fn to_raw(self) -> usize

The packed value, for an FFI that carries a handle as size_t.

Source

pub const fn from_raw(raw: usize) -> HandleId

Rebuild a handle from to_raw’s value. Any value is accepted: a value no registration issued fails every lookup.

Trait Implementations§

Source§

impl BitOr for HandleId

Source§

type Output = HandleSet

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: HandleId) -> HandleSet

Performs the | operation. Read more
Source§

impl BitOr<HandleId> for HandleSet

Source§

type Output = HandleSet

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: HandleId) -> HandleSet

Performs the | operation. Read more
Source§

impl Clone for HandleId

Source§

fn clone(&self) -> HandleId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for HandleId

Source§

impl Debug for HandleId

Source§

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

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

impl Eq for HandleId

Source§

impl Hash for HandleId

Source§

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

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 PartialEq for HandleId

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HandleId

Auto Trait Implementations§

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