Trait EngineEnum
pub trait EngineEnum: Copy + 'static {
// Required methods
fn try_from_ord(ord: i32) -> Option<Self>;
fn ord(self) -> i32;
fn as_str(&self) -> &'static str;
fn values() -> &'static [Self];
fn all_constants() -> &'static [EnumConstant<Self>];
// Provided method
fn from_ord(ord: i32) -> Self { ... }
}Expand description
Auto-implemented for all engine-provided enums.
§Future direction: GodotEnum unification
Currently engine enums implement this trait with all_constants() returning &[EnumConstant<Self>], while user enums provide
metadata through GodotShape::Enum with &[Enumerator]. A future GodotEnum trait could unify both, providing a single
interface for enumerator introspection, constant registration via classdb_register_extension_class_integer_constant (which
also accepts p_is_bitfield), and shared GodotShape construction. This would let user enums opt-in to the same capabilities
as engine enums (GDScript name resolution, editor integration).
Required Methods§
fn try_from_ord(ord: i32) -> Option<Self>
fn ord(self) -> i32
fn ord(self) -> i32
Ordinal value of the enumerator, as specified in Godot. This is not necessarily unique.
fn as_str(&self) -> &'static str
fn as_str(&self) -> &'static str
The name of the enumerator, as it appears in Rust.
Note that this may not match the Rust constant name. In case of multiple constants with the same ordinal value, this method returns
the first one in the order of definition. For example, LayoutDirection::LOCALE.as_str()
(ord 1) returns "APPLICATION_LOCALE", because that happens to be the first constant with ordinal 1.
See all_constants() for a more robust and general approach to introspection of enum constants.
If the value does not match one of the known enumerators, the empty string is returned.
fn values() -> &'static [Self]
fn values() -> &'static [Self]
Returns a slice of distinct enum values.
This excludes MAX constants at the end (existing only to express the number of enumerators) and deduplicates aliases,
providing only meaningful enum values. See all_constants() for a complete list of all constants.
Enables iteration over distinct enum variants:
use godot::classes::window;
use godot::obj::EngineEnum;
for mode in window::Mode::values() {
println!("* {}: {}", mode.as_str(), mode.ord());
}fn all_constants() -> &'static [EnumConstant<Self>]
fn all_constants() -> &'static [EnumConstant<Self>]
Returns metadata for all enum constants.
This includes all constants as they appear in the enum definition, including duplicates and MAX constants.
For a list of useful, distinct values, use values().
Enables introspection of available constants:
use godot::classes::window;
use godot::obj::EngineEnum;
for constant in window::Mode::all_constants() {
println!("* window::Mode.{} (original {}) has ordinal value {}.",
constant.rust_name(),
constant.godot_name(),
constant.value().ord()
);
}Provided Methods§
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.