Struct 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>

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 duplicate of the value. Read more
1.0.0 · Source§

const 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>

Source§

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> Freeze for TRef<'a, T, Own>

§

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

§

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

§

impl<'a, T, Own> Sync for TRef<'a, T, Own>
where T: Sync, Own: 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 T: RefUnwindSafe, Own: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> OwnedToVariant for T
where T: ToVariant,

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> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

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

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

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.