Skip to main content

ObjectHandle

Struct ObjectHandle 

Source
pub struct ObjectHandle { /* private fields */ }
Expand description

A handle to an object managed by the object registry

Handles are lightweight, copyable references that include:

  • object_type: The type of object being referenced
  • id: Unique identifier for this object
  • generation: Counter incremented each time an ID is reused

The generation counter prevents the ABA problem where an object is deleted and a new object reuses the same ID.

§Examples

use scarab_plugin_api::object_model::{ObjectHandle, ObjectType};

let handle = ObjectHandle::new(ObjectType::Window, 42, 1);
assert_eq!(handle.id(), 42);
assert_eq!(handle.object_type(), ObjectType::Window);
assert_eq!(handle.generation(), 1);

Implementations§

Source§

impl ObjectHandle

Source

pub const fn new(object_type: ObjectType, id: u64, generation: u32) -> Self

Create a new object handle

§Arguments
  • object_type - The type of object this handle references
  • id - Unique identifier for this object
  • generation - Generation counter for detecting stale handles
Source

pub const fn object_type(&self) -> ObjectType

Get the object type

Source

pub const fn id(&self) -> u64

Get the object ID

Source

pub const fn generation(&self) -> u32

Get the generation counter

Source

pub const fn is_valid(&self, current_generation: u32) -> bool

Check if this handle is valid for the given generation

Returns true if the handle’s generation matches the provided generation, indicating the handle is still valid and hasn’t been invalidated by object deletion/recreation.

§Examples
use scarab_plugin_api::object_model::{ObjectHandle, ObjectType};

let handle = ObjectHandle::new(ObjectType::Window, 1, 5);
assert!(handle.is_valid(5));
assert!(!handle.is_valid(6));
Source

pub const fn next_generation(&self) -> Self

Create a new handle with an incremented generation

This is useful when an object is deleted and its ID is reused for a new object.

Trait Implementations§

Source§

impl Clone for ObjectHandle

Source§

fn clone(&self) -> ObjectHandle

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ObjectHandle

Source§

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

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

impl Display for ObjectHandle

Source§

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

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

impl Hash for ObjectHandle

Source§

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

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 ObjectHandle

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ObjectHandle

Source§

impl Eq for ObjectHandle

Source§

impl Send for ObjectHandle

Source§

impl StructuralPartialEq for ObjectHandle

Source§

impl Sync for ObjectHandle

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> CallHasher for T
where T: Hash + ?Sized,

Source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

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<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V