Skip to main content

Pinned

Struct Pinned 

Source
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.
  • Drop removes 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,

Source

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.

Source

pub fn is_alive(&self) -> bool

Check whether the pinned object is still alive (local memory read).

Source

pub fn handle(&self) -> UObjectHandle

Get the underlying raw handle. Guaranteed valid while this Pinned exists and is_alive() returns true.

Source

pub fn as_ref(&self) -> UObjectRef<T>

Borrow as a lightweight UObjectRef. The returned ref is valid as long as this Pinned is alive.

Source

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> Debug for Pinned<T>
where T: UeClass,

Source§

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

Formats the value using the given formatter. Read more
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.

No upcast() on Pinned — it owns a GC root, so consuming would be unsound. Use Deref for borrowed access to parent methods instead.

Source§

type Target = Pinned<<T as HasParent>::Parent>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Pinned<<T as HasParent>::Parent>

Dereferences the value.
Source§

impl<T> Drop for Pinned<T>
where T: UeClass,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T> Send for Pinned<T>
where T: UeClass,

Source§

impl<T> UeHandle for Pinned<T>
where T: UeClass,

Source§

fn checked_handle(&self) -> Result<UObjectHandle, RustealError>

Return the raw handle if the object is alive, or Err(ObjectDestroyed).
Source§

fn raw_handle(&self) -> UObjectHandle

Return the raw handle without validity check.
Source§

impl<T> ValidHandle for Pinned<T>
where T: UeClass,

Source§

fn handle(&self) -> UObjectHandle

Return the raw handle. The implementor guarantees (or debug-asserts) that the handle is valid.

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.