[][src]Struct gdnative_core::Instance

pub struct Instance<T: NativeClass> { /* fields omitted */ }

A reference to a GodotObject with a rust NativeClass attached.

Methods

impl<T: NativeClass> Instance<T>[src]

pub fn new() -> Self where
    T::Base: Instanciable
[src]

Creates a T::Base with the script T attached. Both T::Base and T must have zero argument constructors.

Must be called after the library is initialized.

pub fn into_base(self) -> T::Base[src]

pub fn into_script(self) -> T::UserData[src]

pub fn decouple(self) -> (T::Base, T::UserData)[src]

pub fn base(&self) -> &T::Base[src]

pub fn script(&self) -> &T::UserData[src]

pub fn try_from_base(owner: T::Base) -> Option<Self> where
    T::Base: Clone
[src]

Try to downcast T::Base to Instance<T>. This safe version can only be used with reference counted base classes.

pub unsafe fn try_from_unsafe_base(owner: T::Base) -> Option<Self>[src]

Try to downcast T::Base to Instance<T>.

Safety

It's up to the caller to ensure that owner points to a valid Godot object, and that it will not be freed until this function returns. Otherwise, it is undefined behavior to call this function and/or use its return value.

pub fn map<F, U>(&self, op: F) -> Result<U, <T::UserData as Map>::Err> where
    T::Base: Clone,
    T::UserData: Map,
    F: FnOnce(&T, T::Base) -> U, 
[src]

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::UserData as MapMut>::Err> where
    T::Base: Clone,
    T::UserData: MapMut,
    F: FnOnce(&mut T, T::Base) -> U, 
[src]

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 unsafe fn map_aliased<F, U>(
    &self,
    op: F
) -> Result<U, <T::UserData as Map>::Err> where
    T::UserData: Map,
    F: FnOnce(&T, T::Base) -> U, 
[src]

Calls a function with a NativeClass instance and its owner, and returns its return value. Can be used for multiple times via aliasing:

This example is not tested
unsafe {
    instance.map_aliased(/* ... */);
    // instance.owner may be invalid now, but you can still:
    instance.map_aliased(/* ... */);
    instance.map_aliased(/* ... */); // ...for multiple times
}

For reference-counted types behaves like the safe map, which should be preferred.

pub unsafe fn map_mut_aliased<F, U>(
    &self,
    op: F
) -> Result<U, <T::UserData as MapMut>::Err> where
    T::UserData: MapMut,
    F: FnOnce(&mut T, T::Base) -> U, 
[src]

Calls a function with a NativeClass instance and its owner, and returns its return value. Can be used for multiple times via aliasing:

This example is not tested
unsafe {
    instance.map_mut_aliased(/* ... */);
    // instance.owner may be invalid now, but you can still:
    instance.map_mut_aliased(/* ... */);
    instance.map_mut_aliased(/* ... */); // ...for multiple times
}

For reference-counted types behaves like the safe map_mut, which should be preferred.

Trait Implementations

impl<T> Clone for Instance<T> where
    T: NativeClass,
    T::Base: Clone
[src]

impl<T: Debug + NativeClass> Debug for Instance<T> where
    T::Base: Debug,
    T::UserData: Debug
[src]

impl<T: Eq + NativeClass> Eq for Instance<T> where
    T::Base: Eq,
    T::UserData: Eq
[src]

impl<T> Export for Instance<T> where
    T: NativeClass,
    T::Base: ToVariant
[src]

type Hint = ()

A type-specific hint type that is valid for the type being exported.

impl<T> FromVariant for Instance<T> where
    T: NativeClass,
    T::Base: FromVariant + Clone
[src]

impl<T: Ord + NativeClass> Ord for Instance<T> where
    T::Base: Ord,
    T::UserData: Ord
[src]

impl<T: PartialEq + NativeClass> PartialEq<Instance<T>> for Instance<T> where
    T::Base: PartialEq,
    T::UserData: PartialEq
[src]

impl<T: PartialOrd + NativeClass> PartialOrd<Instance<T>> for Instance<T> where
    T::Base: PartialOrd,
    T::UserData: PartialOrd
[src]

impl<T: NativeClass> StructuralEq for Instance<T>[src]

impl<T: NativeClass> StructuralPartialEq for Instance<T>[src]

impl<T> ToVariant for Instance<T> where
    T: NativeClass,
    T::Base: ToVariant
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Instance<T> where
    <T as NativeClass>::Base: RefUnwindSafe,
    <T as NativeClass>::UserData: RefUnwindSafe

impl<T> Send for Instance<T> where
    <T as NativeClass>::Base: Send,
    <T as NativeClass>::UserData: Send

impl<T> Sync for Instance<T> where
    <T as NativeClass>::Base: Sync,
    <T as NativeClass>::UserData: Sync

impl<T> Unpin for Instance<T> where
    <T as NativeClass>::Base: Unpin,
    <T as NativeClass>::UserData: Unpin

impl<T> UnwindSafe for Instance<T> where
    <T as NativeClass>::Base: UnwindSafe,
    <T as NativeClass>::UserData: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Export for T where
    T: GodotObject + ToVariant
[src]

type Hint = ()

A type-specific hint type that is valid for the type being exported.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.