Trait GodotDefault
pub trait GodotDefault: GodotClass { }
Expand description
Trait for all classes that are default-constructible from the Godot engine.
Enables the MyClass.new()
syntax in GDScript, and allows the type to be used by the editor, which often default-constructs objects.
This trait is automatically implemented for the following classes:
- User defined classes if either:
- they override an
init()
method - they have
#[class(init)]
attribute
- they override an
- Engine classes if:
- they are reference-counted and constructible (i.e. provide a
new()
method).
- they are reference-counted and constructible (i.e. provide a
This trait is not manually implemented, and you cannot call any methods. You can use it as a bound, but typically you’d use
it indirectly through Gd::default()
. Note that Gd::default()
has an additional requirement on
being reference-counted, meaning not every GodotDefault
class can automatically be used with Gd::default()
.
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.