Trait ToGodot
pub trait ToGodot: Sized + GodotConvert {
type Pass: ArgPassing;
type Threads: ThreadSafety;
// Required method
fn to_godot(&self) -> <Self::Pass as ArgPassing>::Output<'_, Self::Via>;
// Provided methods
fn to_godot_owned(&self) -> Self::Via { ... }
fn to_variant(&self) -> Variant { ... }
}Expand description
Defines the canonical conversion to Godot for a type.
It is assumed that all the methods return equal values given equal inputs. Additionally, it is assumed
that if FromGodot is implemented, converting to Godot and back again will return a value equal to the
starting value.
Violating these assumptions is safe but will give unexpected results.
Please read the godot::meta module docs for further information about conversions.
This trait can be derived using the #[derive(GodotConvert)] macro.
Required Associated Types§
type Pass: ArgPassing
type Pass: ArgPassing
Whether arguments of this type are passed by value or by reference.
Can be either ByValue or ByRef. In most cases, you need ByValue.
Select ByValue if:
SelfisCopy(e.g.i32,f64,Vector2,Color, etc).- You need a conversion (e.g.
Self = MyString,Via = GString). - You like the simple life and can’t be bothered with lifetimes.
Select ByRef if:
- Performance of argument passing is very important and you have measured it.
- You store a cached value which can be borrowed (e.g.
&GString).
Will auto-implement AsArg<T> for either T (by-value) or for &T (by-reference).
This has an influence on contexts such as Array::push(), the array![...]
macro or generated signal emit() signatures.
type Threads: ThreadSafety
type Threads: ThreadSafety
Whether arguments of this type are thread-safe or not.
Can be either ThreadSafeArg or NonThreadSafeArg. Only engine
types make use of NonThreadSafeArg, all user defined types should use ThreadSafeArg by deriving GodotConvert or by manually
implementing this trait. The use of ThreadSafeArg also requires the type to be Send. Non Send user defined types are
currenlty not supported.
Required Methods§
fn to_godot(&self) -> <Self::Pass as ArgPassing>::Output<'_, Self::Via>
fn to_godot(&self) -> <Self::Pass as ArgPassing>::Output<'_, Self::Via>
Provided Methods§
fn to_godot_owned(&self) -> Self::Via
fn to_godot_owned(&self) -> Self::Via
Converts this type to owned Godot representation.
Always returns Self::Via, cloning if necessary for ByRef types.
§Panics
See to_godot().
fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.