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>
impl<'a, T: GodotObject, Own: Ownership> TRef<'a, T, Own>
sourcepub fn cast<U>(self) -> Option<TRef<'a, U, Own>>where
U: GodotObject + SubClass<T>,
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.
sourcepub fn upcast<U>(&self) -> TRef<'a, U, Own>where
U: GodotObject,
T: SubClass<U>,
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.
sourcepub fn cast_instance<C>(self) -> Option<TInstance<'a, C, Own>>where
C: NativeClass<Base = T>,
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,
impl<'a, Kind, T, Own> TRef<'a, T, Own>where
Kind: Memory,
T: GodotObject<Memory = Kind>,
Own: NonUniqueOwnership,
sourcepub unsafe fn try_from_instance_id(id: i64) -> Option<Self>
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.
sourcepub unsafe fn from_instance_id(id: i64) -> Self
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.