pub struct Pinned<T>where
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.
#[repr(C)] guarantees deterministic layout so that the blanket Deref
pointer cast (&Pinned<T> → &Pinned<T::Parent>) is sound.
Implementations§
Source§impl<T> Pinned<T>where
T: UeClass,
impl<T> Pinned<T>where
T: UeClass,
Sourcepub fn new(obj: UObjectRef<T>) -> Result<Pinned<T>, RustealError>
pub fn new(obj: UObjectRef<T>) -> Result<Pinned<T>, RustealError>
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> Deref for Pinned<T>where
T: HasParent,
Blanket Deref: Pinned<Child> auto-derefs to Pinned<Parent>.
Safe because Pinned<T> is #[repr(C)] and PhantomData is zero-sized,
so Pinned<T> and Pinned<T::Parent> have identical layout.
impl<T> Deref for Pinned<T>where
T: HasParent,
Blanket Deref: Pinned<Child> auto-derefs to Pinned<Parent>.
Safe because Pinned<T> is #[repr(C)] and PhantomData is zero-sized,
so Pinned<T> and Pinned<T::Parent> have identical layout.
No upcast() on Pinned — it owns a GC root, so consuming would be unsound.
Use Deref for borrowed access to parent methods instead.
impl<T> Send for Pinned<T>where
T: UeClass,
Source§impl<T> UeHandle for Pinned<T>where
T: UeClass,
impl<T> UeHandle for Pinned<T>where
T: UeClass,
Source§fn checked_handle(&self) -> Result<UObjectHandle, RustealError>
fn checked_handle(&self) -> Result<UObjectHandle, RustealError>
Err(ObjectDestroyed).