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.
§Result<T, E>
It is possible to return Result<T, E> from #[func], when T: ToGodot and E: ErrorToGodot.
However, Result<T, E> currently does not implement ToGodot itself, as it is not generally infallible.
§Panics
Currently, the methods to_godot(), to_godot_owned() and to_variant() are infallible and never panic, i.e. you can convert every value
to a Godot representation. If new types are supported in the future that may not satisfy this (example: Result<T, E>), it’s possible
that panics are introduced only for those new types.
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§
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.
fn to_variant(&self) -> Variant
fn to_variant(&self) -> Variant
Converts this type to a 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.