pub struct Pinned<T: UeClass> { /* private fields */ }Expand description
An owning GC root for a UObject.
!Copy,!Clone— unique ownership of the GC root.Send— can be moved across threads.!Sync— must only be used on the game thread.Dropremoves the GC root and unregisters from destroy notification.
Method calls on Pinned<T> use a local alive flag (~1-3 cycles) instead
of an FFI is_valid call (~15-30 cycles) for validity checking.
Implementations§
Source§impl<T: UeClass> Pinned<T>
impl<T: UeClass> Pinned<T>
Sourcepub fn new(obj: UObjectRef<T>) -> UikaResult<Self>
pub fn new(obj: UObjectRef<T>) -> UikaResult<Self>
Pin an object by adding a GC root and registering for destroy notification. Fails if the object is already destroyed.
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Check whether the pinned object is still alive (local memory read).
Sourcepub fn handle(&self) -> UObjectHandle
pub fn handle(&self) -> UObjectHandle
Get the underlying raw handle. Guaranteed valid while this Pinned
exists and is_alive() returns true.
Sourcepub fn as_ref(&self) -> UObjectRef<T>
pub fn as_ref(&self) -> UObjectRef<T>
Borrow as a lightweight UObjectRef. The returned ref is valid as long
as this Pinned is alive.
Sourcepub fn as_checked(&self) -> Checked<T>
pub fn as_checked(&self) -> Checked<T>
Create a Checked<T> handle from this pinned reference.
Valid as long as is_alive() returns true (debug-asserted).
Trait Implementations§
Source§impl<T: UeClass> UeHandle for Pinned<T>
impl<T: UeClass> UeHandle for Pinned<T>
Source§fn checked_handle(&self) -> UikaResult<UObjectHandle>
fn checked_handle(&self) -> UikaResult<UObjectHandle>
Return the raw handle if the object is alive, or
Err(ObjectDestroyed).Source§fn raw_handle(&self) -> UObjectHandle
fn raw_handle(&self) -> UObjectHandle
Return the raw handle without validity check.
Source§impl<T: UeClass> ValidHandle for Pinned<T>
impl<T: UeClass> ValidHandle for Pinned<T>
Source§fn handle(&self) -> UObjectHandle
fn handle(&self) -> UObjectHandle
Return the raw handle. The implementor guarantees (or debug-asserts)
that the handle is valid.
impl<T: UeClass> Send for Pinned<T>
Auto Trait Implementations§
impl<T> Freeze for Pinned<T>
impl<T> RefUnwindSafe for Pinned<T>where
T: RefUnwindSafe,
impl<T> !Sync for Pinned<T>
impl<T> Unpin for Pinned<T>
impl<T> UnsafeUnpin for Pinned<T>
impl<T> UnwindSafe for Pinned<T>where
T: RefUnwindSafe,
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