[][src]Struct gdnative::Instance

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

A reference to a GodotObject with a rust NativeClass attached.

Methods

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

pub fn new() -> Instance<T> where
    <T as NativeClass>::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 as NativeClass>::Base[src]

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

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

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

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

pub fn try_from_base(owner: <T as NativeClass>::Base) -> Option<Instance<T>> where
    <T as NativeClass>::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 as NativeClass>::Base
) -> Option<Instance<T>>
[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 as NativeClass>::UserData as Map>::Err> where
    F: FnOnce(&T, <T as NativeClass>::Base) -> U,
    <T as NativeClass>::Base: Clone,
    <T as NativeClass>::UserData: Map
[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 as NativeClass>::UserData as MapMut>::Err> where
    F: FnOnce(&mut T, <T as NativeClass>::Base) -> U,
    <T as NativeClass>::Base: Clone,
    <T as NativeClass>::UserData: MapMut
[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 as NativeClass>::UserData as Map>::Err> where
    F: FnOnce(&T, <T as NativeClass>::Base) -> U,
    <T as NativeClass>::UserData: Map
[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 as NativeClass>::UserData as MapMut>::Err> where
    F: FnOnce(&mut T, <T as NativeClass>::Base) -> U,
    <T as NativeClass>::UserData: MapMut
[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 as NativeClass>::Base: Clone
[src]

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

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

impl<T> Export for Instance<T> where
    T: NativeClass,
    <T as NativeClass>::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 as NativeClass>::Base: FromVariant,
    <T as NativeClass>::Base: Clone
[src]

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

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

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

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

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

impl<T> ToVariant for Instance<T> where
    T: NativeClass,
    <T as NativeClass>::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.