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);
// Provided method
fn var_hint() -> PropertyHintInfo { ... }
}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_set(field: &mut Self, value: Self::Via)
fn var_set(field: &mut Self, value: Self::Via)
Set property value. Called when writing a property from Godot.
fn var_pub_get(field: &Self) -> Self::PubType
fn var_pub_get(field: &Self) -> Self::PubType
Get property value in a Rust auto-generated getter, for fields annotated with #[var(pub)].
fn var_pub_set(field: &mut Self, value: Self::PubType)
fn var_pub_set(field: &mut Self, value: Self::PubType)
Set property value in a Rust auto-generated setter, for fields annotated with #[var(pub)].
Provided Methods§
fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
Specific property hints. Only override if they deviate from GodotType::property_info, e.g. for enums/newtypes.
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.