Struct gdnative_core::object::TRef

source ·
pub struct TRef<'a, T: GodotObject, Own: Ownership = Shared> { /* private fields */ }
Expand description

A temporary safe pointer to Godot objects that tracks thread access status. TRef can be coerced into bare references with Deref.

See the type-level documentation on Ref for detailed documentation on the reference system of godot-rust.

Using as method arguments or return values

TRef<T, Shared> can be passed into methods.

Using as owner arguments in NativeScript methods

It’s possible to use TRef as the owner argument in NativeScript methods. This can make passing owner to methods easier.

Implementations§

source§

impl<'a, T: GodotObject, Own: Ownership> TRef<'a, T, Own>

source

pub fn as_ref(self) -> &'a T

Returns the underlying reference without thread access.

source

pub fn cast<U>(self) -> Option<TRef<'a, U, Own>>where
    U: GodotObject + SubClass<T>,

Performs a dynamic reference cast to target type, keeping the thread access info.

source

pub fn upcast<U>(&self) -> TRef<'a, U, Own>where
    U: GodotObject,
    T: SubClass<U>,

Performs a static reference upcast to a supertype that is guaranteed to be valid, keeping the thread access info.

This is guaranteed to be a no-op at runtime.

source

pub fn cast_instance<C>(self) -> Option<TInstance<'a, C, Own>>where
    C: NativeClass<Base = T>,

Convenience method to downcast to TInstance where self is the base object.

source§

impl<'a, Kind, T, Own> TRef<'a, T, Own>where
    Kind: Memory,
    T: GodotObject<Memory = Kind>,
    Own: NonUniqueOwnership,

source

pub fn claim(self) -> Ref<T, Own>

Persists this reference into a persistent Ref with the same thread access.

This is only available for non-Unique accesses.

source§

impl<'a, T: GodotObject> TRef<'a, T, Shared>

source

pub unsafe fn try_from_instance_id(id: i64) -> Option<Self>

Recovers a instance ID previously returned by Object::get_instance_id if the object is still alive.

Safety

During the entirety of 'a, the thread from which try_from_instance_id is called must have exclusive access to the underlying object, if it is still alive.

source

pub unsafe fn from_instance_id(id: i64) -> Self

Recovers a instance ID previously returned by Object::get_instance_id if the object is still alive, and panics otherwise. This does NOT guarantee that the resulting reference is safe to use.

Panics

Panics if the given id refers to a destroyed object. For a non-panicking version, see try_from_instance_id.

Safety

During the entirety of 'a, the thread from which try_from_instance_id is called must have exclusive access to the underlying object, if it is still alive.

Trait Implementations§

source§

impl<'a, T: GodotObject, Own: Ownership> AsRef<T> for TRef<'a, T, Own>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a, T: GodotObject> AsVariant for TRef<'a, T, Shared>

§

type Target = T

source§

impl<'a, T: GodotObject, Own: Ownership> Borrow<T> for TRef<'a, T, Own>

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<'a, T: GodotObject, Own: Ownership> Clone for TRef<'a, T, Own>

source§

fn clone(&self) -> Self

Returns a copy 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<'a, T: GodotObject, Own: Ownership> Debug for TRef<'a, T, Own>

source§

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

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

impl<'a, T: GodotObject, Own: Ownership> Deref for TRef<'a, T, Own>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'a, T: GodotObject> ToVariant for TRef<'a, T, Shared>

source§

impl<'a, T, U> AsArg<U> for TRef<'a, T, Shared>where
    T: GodotObject + SubClass<U>,
    U: GodotObject,

source§

impl<'a, T: GodotObject, Own: Ownership> Copy for TRef<'a, T, Own>

source§

impl<'a, T, Own> OwnerArg<'a, T, Own> for TRef<'a, T, Own>where
    T: GodotObject,
    Own: Ownership + 'static,

Auto Trait Implementations§

§

impl<'a, T, Own> RefUnwindSafe for TRef<'a, T, Own>where
    Own: RefUnwindSafe,
    T: RefUnwindSafe,

§

impl<'a, T, Own> Send for TRef<'a, T, Own>where
    Own: Send,
    T: Sync,

§

impl<'a, T, Own> Sync for TRef<'a, T, Own>where
    Own: Sync,
    T: Sync,

§

impl<'a, T, Own> Unpin for TRef<'a, T, Own>where
    Own: Unpin,

§

impl<'a, T, Own> UnwindSafe for TRef<'a, T, Own>where
    Own: UnwindSafe,
    T: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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> ToOwned for Twhere
    T: Clone,

§

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, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.