Struct gdnative::nativescript::Instance [−][src]
A persistent reference to a GodotObject with a rust NativeClass attached.
Instance
s can be worked on directly using map
and map_mut
if the base object is
reference-counted. Otherwise, use assume_safe
to obtain a temporary RefInstance
.
See the type-level documentation on Ref
for more information on typed thread accesses.
Implementations
impl<T> Instance<T, Unique> where
T: NativeClass,
[src]
T: NativeClass,
pub fn new() -> Instance<T, Unique> where
<T as NativeClass>::Base: Instanciable,
[src]
<T as NativeClass>::Base: Instanciable,
Creates a T::Base
with the script T
attached. Both T::Base
and T
must have zero
argument constructors.
If T::Base
is manually-managed, then the resulting Instance
must be passed to
the engine or manually freed with Instance::free
. Otherwise, the base object will be
leaked.
Must be called after the library is initialized.
pub fn emplace(script: T) -> Instance<T, Unique> where
<T as NativeClass>::Base: Instanciable,
[src]
<T as NativeClass>::Base: Instanciable,
Creates a T::Base
with a given instance of the script T
attached. T::Base
must
have a zero-argument constructor.
This may be used to create instances of scripts that do not have zero-argument constructors:
// This type does not have a zero-argument constructor. As a result, `Instance::new` // will panic and `Foo.new` from GDScript will result in errors when the object is used. #[derive(NativeScript)] #[inherit(Reference)] #[no_constructor] struct MyIntVector(i64, i64); #[methods] impl MyIntVector { // - snip - } // With `Instance::emplace`, however, we can expose "constructors" from a factory // auto-load for our script type. #[derive(NativeScript)] #[inherit(Node)] #[user_data(Aether<Self>)] struct MyIntVectorFactory; #[methods] impl MyIntVectorFactory { #[export] fn make(&self, _owner: &Node, x: i64, y: i64) -> Instance<MyIntVector, Unique> { Instance::emplace(MyIntVector(x, y)) } }
If T::Base
is manually-managed, then the resulting Instance
must be passed to
the engine or manually freed with Instance::free
. Otherwise, the base object will be
leaked.
Must be called after the library is initialized.
impl<T, Access> Instance<T, Access> where
Access: ThreadAccess,
T: NativeClass,
[src]
Access: ThreadAccess,
T: NativeClass,
pub fn into_base(self) -> Ref<<T as NativeClass>::Base, Access>
[src]
Returns the base object, dropping the script wrapper.
pub fn into_script(self) -> <T as NativeClass>::UserData
[src]
Returns the script wrapper.
pub fn decouple(
self
) -> (Ref<<T as NativeClass>::Base, Access>, <T as NativeClass>::UserData)
[src]
self
) -> (Ref<<T as NativeClass>::Base, Access>, <T as NativeClass>::UserData)
Returns the base object and the script wrapper.
pub fn base(&self) -> &Ref<<T as NativeClass>::Base, Access>
[src]
Returns a reference to the base object.
pub fn script(&self) -> &<T as NativeClass>::UserData
[src]
Returns a reference to the script wrapper.
impl<T, Access> Instance<T, Access> where
Access: ThreadAccess,
T: NativeClass,
RefImplBound: SafeAsRaw<<<T as NativeClass>::Base as GodotObject>::RefKind, Access>,
[src]
Access: ThreadAccess,
T: NativeClass,
RefImplBound: SafeAsRaw<<<T as NativeClass>::Base as GodotObject>::RefKind, Access>,
pub fn try_from_base(
owner: Ref<<T as NativeClass>::Base, Access>
) -> Result<Instance<T, Access>, Ref<<T as NativeClass>::Base, Access>>
[src]
owner: Ref<<T as NativeClass>::Base, Access>
) -> Result<Instance<T, Access>, Ref<<T as NativeClass>::Base, Access>>
Try to downcast Ref<T::Base, Access>
to Instance<T>
, without changing the reference
count if reference-counted.
Errors
Returns the original Ref
if the cast failed.
pub fn from_base(
owner: Ref<<T as NativeClass>::Base, Access>
) -> Option<Instance<T, Access>>
[src]
owner: Ref<<T as NativeClass>::Base, Access>
) -> Option<Instance<T, Access>>
Try to downcast Ref<T::Base, Access>
to Instance<T>
, without changing the reference
count if reference-counted. Shorthand for Self::try_from_base().ok()
.
impl<T, Access> Instance<T, Access> where
Access: ThreadAccess,
T: NativeClass,
RefImplBound: SafeDeref<<<T as NativeClass>::Base as GodotObject>::RefKind, Access>,
[src]
Access: ThreadAccess,
T: NativeClass,
RefImplBound: SafeDeref<<<T as NativeClass>::Base as GodotObject>::RefKind, Access>,
pub fn map<F, U>(
&self,
op: F
) -> Result<U, <<T as NativeClass>::UserData as Map>::Err> where
F: FnOnce(&T, TRef<'_, <T as NativeClass>::Base, Access>) -> U,
<T as NativeClass>::UserData: Map,
[src]
&self,
op: F
) -> Result<U, <<T as NativeClass>::UserData as Map>::Err> where
F: FnOnce(&T, TRef<'_, <T as NativeClass>::Base, Access>) -> U,
<T as NativeClass>::UserData: Map,
Calls a function with a NativeClass instance and its owner, and returns its return value. Can be used on reference counted types for multiple times.
pub fn map_mut<F, U>(
&self,
op: F
) -> Result<U, <<T as NativeClass>::UserData as MapMut>::Err> where
F: FnOnce(&mut T, TRef<'_, <T as NativeClass>::Base, Access>) -> U,
<T as NativeClass>::UserData: MapMut,
[src]
&self,
op: F
) -> Result<U, <<T as NativeClass>::UserData as MapMut>::Err> where
F: FnOnce(&mut T, TRef<'_, <T as NativeClass>::Base, Access>) -> U,
<T as NativeClass>::UserData: MapMut,
Calls a function with a NativeClass instance and its owner, and returns its return value. Can be used on reference counted types for multiple times.
impl<T> Instance<T, Shared> where
T: NativeClass,
[src]
T: NativeClass,
Methods for instances with manually-managed base classes.
pub unsafe fn assume_safe<'a, 'r>(&'r self) -> RefInstance<'a, T, Shared> where
AssumeSafeLifetime<'a, 'r>: LifetimeConstraint<<<T as NativeClass>::Base as GodotObject>::RefKind>,
[src]
AssumeSafeLifetime<'a, 'r>: LifetimeConstraint<<<T as NativeClass>::Base as GodotObject>::RefKind>,
Assume that self
is safe to use.
This is not guaranteed to be a no-op at runtime.
Safety
It's safe to call assume_safe
only if the constraints of Ref::assume_safe
are satisfied for the base object.
impl<T> Instance<T, Shared> where
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == ManuallyManaged,
[src]
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == ManuallyManaged,
pub unsafe fn is_instance_sane(&self) -> bool
[src]
Returns true
if the pointer currently points to a valid object of the correct type.
This does NOT guarantee that it's safe to use this pointer.
Safety
This thread must have exclusive access to the object during the call.
impl<T> Instance<T, Unique> where
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == ManuallyManaged,
[src]
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == ManuallyManaged,
impl<T> Instance<T, Unique> where
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<T as NativeClass>::Base: QueueFree,
<<T as NativeClass>::Base as GodotObject>::RefKind == ManuallyManaged,
[src]
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<T as NativeClass>::Base: QueueFree,
<<T as NativeClass>::Base as GodotObject>::RefKind == ManuallyManaged,
pub fn queue_free(self)
[src]
Queues the base object and user-data wrapper for deallocation in the near future.
This should be preferred to free
for Node
s.
Same as self.into_base().queue_free()
.
impl<T> Instance<T, Unique> where
T: NativeClass,
[src]
T: NativeClass,
pub fn into_shared(self) -> Instance<T, Shared>
[src]
Coverts into a Shared
instance.
impl<T> Instance<T, Unique> where
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == RefCounted,
[src]
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == RefCounted,
pub fn into_thread_local(self) -> Instance<T, ThreadLocal>
[src]
Coverts into a ThreadLocal
instance.
impl<T> Instance<T, Shared> where
T: NativeClass,
[src]
T: NativeClass,
pub unsafe fn assume_unique(self) -> Instance<T, Unique>
[src]
Assume that self
is the unique reference to the underlying base object.
This is guaranteed to be a no-op at runtime if debug_assertions
is disabled. Runtime
sanity checks may be added in debug builds to help catch bugs.
Safety
Calling assume_unique
when self
isn't the unique reference is instant undefined
behavior. This is a much stronger assumption than assume_safe
and should be used with
care.
impl<T> Instance<T, Shared> where
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == RefCounted,
[src]
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == RefCounted,
pub unsafe fn assume_thread_local(self) -> Instance<T, ThreadLocal>
[src]
Assume that all references to the underlying object is local to the current thread.
This is guaranteed to be a no-op at runtime.
Safety
Calling assume_thread_local
when there are references on other threads is instant
undefined behavior. This is a much stronger assumption than assume_safe
and should
be used with care.
Trait Implementations
impl<T, Access> Clone for Instance<T, Access> where
Access: ThreadAccess,
T: NativeClass,
Ref<<T as NativeClass>::Base, Access>: Clone,
[src]
Access: ThreadAccess,
T: NativeClass,
Ref<<T as NativeClass>::Base, Access>: Clone,
pub fn clone(&self) -> Instance<T, Access>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T, Access> Debug for Instance<T, Access> where
Access: ThreadAccess + Debug,
T: NativeClass + Debug,
<T as NativeClass>::Base: Debug,
<T as NativeClass>::UserData: Debug,
[src]
Access: ThreadAccess + Debug,
T: NativeClass + Debug,
<T as NativeClass>::Base: Debug,
<T as NativeClass>::UserData: Debug,
impl<T> Export for Instance<T, Shared> where
T: NativeClass,
Instance<T, Shared>: ToVariant,
[src]
T: NativeClass,
Instance<T, Shared>: ToVariant,
type Hint = ()
A type-specific hint type that is valid for the type being exported.
pub fn export_info(
_hint: Option<<Instance<T, Shared> as Export>::Hint>
) -> ExportInfo
[src]
_hint: Option<<Instance<T, Shared> as Export>::Hint>
) -> ExportInfo
impl<T> FromVariant for Instance<T, Shared> where
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == RefCounted,
[src]
T: NativeClass,
<T as NativeClass>::Base: GodotObject,
<<T as NativeClass>::Base as GodotObject>::RefKind == RefCounted,
pub fn from_variant(
variant: &Variant
) -> Result<Instance<T, Shared>, FromVariantError>
[src]
variant: &Variant
) -> Result<Instance<T, Shared>, FromVariantError>
impl<T> OwnedToVariant for Instance<T, Unique> where
T: NativeClass,
[src]
T: NativeClass,
pub fn owned_to_variant(self) -> Variant
[src]
impl<T, Access> ToVariant for Instance<T, Access> where
Access: ThreadAccess,
T: NativeClass,
Ref<<T as NativeClass>::Base, Access>: ToVariant,
[src]
Access: ThreadAccess,
T: NativeClass,
Ref<<T as NativeClass>::Base, Access>: ToVariant,
pub fn to_variant(&self) -> Variant
[src]
Auto Trait Implementations
impl<T, Access> RefUnwindSafe for Instance<T, Access> where
Access: RefUnwindSafe,
<T as NativeClass>::Base: RefUnwindSafe,
<<<T as NativeClass>::Base as GodotObject>::RefKind as RefKindSpec>::PtrWrapper: RefUnwindSafe,
<T as NativeClass>::UserData: RefUnwindSafe,
[src]
Access: RefUnwindSafe,
<T as NativeClass>::Base: RefUnwindSafe,
<<<T as NativeClass>::Base as GodotObject>::RefKind as RefKindSpec>::PtrWrapper: RefUnwindSafe,
<T as NativeClass>::UserData: RefUnwindSafe,
impl<T, Access> Send for Instance<T, Access> where
Access: Send,
<T as NativeClass>::UserData: Send,
[src]
Access: Send,
<T as NativeClass>::UserData: Send,
impl<T, Access> Sync for Instance<T, Access> where
Access: Sync,
<T as NativeClass>::UserData: Sync,
[src]
Access: Sync,
<T as NativeClass>::UserData: Sync,
impl<T, Access> Unpin for Instance<T, Access> where
Access: Unpin,
<<<T as NativeClass>::Base as GodotObject>::RefKind as RefKindSpec>::PtrWrapper: Unpin,
<T as NativeClass>::UserData: Unpin,
[src]
Access: Unpin,
<<<T as NativeClass>::Base as GodotObject>::RefKind as RefKindSpec>::PtrWrapper: Unpin,
<T as NativeClass>::UserData: Unpin,
impl<T, Access> UnwindSafe for Instance<T, Access> where
Access: UnwindSafe,
<T as NativeClass>::Base: RefUnwindSafe,
<<<T as NativeClass>::Base as GodotObject>::RefKind as RefKindSpec>::PtrWrapper: UnwindSafe,
<T as NativeClass>::UserData: UnwindSafe,
[src]
Access: UnwindSafe,
<T as NativeClass>::Base: RefUnwindSafe,
<<<T as NativeClass>::Base as GodotObject>::RefKind as RefKindSpec>::PtrWrapper: UnwindSafe,
<T as NativeClass>::UserData: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> OwnedToVariant for T where
T: ToVariant,
[src]
T: ToVariant,
pub fn owned_to_variant(self) -> Variant
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,