Trait Var
pub trait Var: GodotConvert {
type PubType;
// Required methods
fn var_get(field: &Self) -> Self::Via;
fn var_set(field: &mut Self, value: Self::Via);
fn var_pub_get(field: &Self) -> Self::PubType;
fn var_pub_set(field: &mut Self, value: Self::PubType);
}Expand description
Trait for types used in #[var] fields.
Defines how a value is passed to/from Godot’s property system, through var_get() and var_set()
associated functions. Further customizes how generated Rust getters and setters operate, in fields annotated with #[var(pub)], through
var_pub_get() and var_pub_set().
The Var trait does not require FromGodot or ToGodot: a value can be used as a property even if it can’t be used in #[func]
parameters or return types.
See also Export, a subtrait for properties exported to the editor UI using #[export].
§Implementing the trait
Most godot-rust types implement Var out of the box, so you won’t need to do anything. If a type doesn’t support it, that’s usually a sign
that it shouldn’t be used in property contexts.
For enums, you can use the #[derive(Var)] macro, in combination with GodotConvert as #[derive(GodotConvert, Var)].
If you need to manually implement Var and your field type already supports ToGodot and FromGodot, just implement the SimpleVar
trait instead of Var. It will automatically provide a reasonable standard implementation of Var.
Required Associated Types§
type PubType
type PubType
Type used in generated Rust getters/setters for #[var(pub)].
Required Methods§
fn var_get(field: &Self) -> Self::Via
fn var_get(field: &Self) -> Self::Via
Get property value via FFI-level Via type. Called for internal (non-pub) getters registered with Godot.
fn var_set(field: &mut Self, value: Self::Via)
fn var_set(field: &mut Self, value: Self::Via)
Set property value via FFI-level Via type. Called for internal (non-pub) setters registered with Godot.
fn var_pub_get(field: &Self) -> Self::PubType
fn var_pub_get(field: &Self) -> Self::PubType
Get property value as PubType. Called for #[var(pub)] getters exposed in Rust API.
fn var_pub_set(field: &mut Self, value: Self::PubType)
fn var_pub_set(field: &mut Self, value: Self::PubType)
Set property value as PubType. Called for #[var(pub)] setters exposed in Rust API.
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.