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 referencedid: Unique identifier for this objectgeneration: 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
impl ObjectHandle
Sourcepub const fn new(object_type: ObjectType, id: u64, generation: u32) -> Self
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 referencesid- Unique identifier for this objectgeneration- Generation counter for detecting stale handles
Sourcepub const fn object_type(&self) -> ObjectType
pub const fn object_type(&self) -> ObjectType
Get the object type
Sourcepub const fn generation(&self) -> u32
pub const fn generation(&self) -> u32
Get the generation counter
Sourcepub const fn is_valid(&self, current_generation: u32) -> bool
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));Sourcepub const fn next_generation(&self) -> Self
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
impl Clone for ObjectHandle
Source§fn clone(&self) -> ObjectHandle
fn clone(&self) -> ObjectHandle
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ObjectHandle
impl Debug for ObjectHandle
Source§impl Display for ObjectHandle
impl Display for ObjectHandle
Source§impl Hash for ObjectHandle
impl Hash for ObjectHandle
Source§impl PartialEq for ObjectHandle
impl PartialEq for ObjectHandle
impl Copy for ObjectHandle
impl Eq for ObjectHandle
impl Send for ObjectHandle
impl StructuralPartialEq for ObjectHandle
impl Sync for ObjectHandle
Auto Trait Implementations§
impl Freeze for ObjectHandle
impl RefUnwindSafe for ObjectHandle
impl Unpin for ObjectHandle
impl UnsafeUnpin for ObjectHandle
impl UnwindSafe for ObjectHandle
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.