Trait EngineEnum

Source
pub trait EngineEnum: Copy {
    // Required methods
    fn try_from_ord(ord: i32) -> Option<Self>;
    fn ord(self) -> i32;
    fn as_str(&self) -> &'static str;
    fn godot_name(&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.

Required Methodsยง

Source

fn try_from_ord(ord: i32) -> Option<Self>

Source

fn ord(self) -> i32

Ordinal value of the enumerator, as specified in Godot. This is not necessarily unique.

Source

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.

Source

fn godot_name(&self) -> &'static str

๐Ÿ‘ŽDeprecated: Moved to introspection API, see EngineEnum::all_constants() and EnumConstant::godot_name()

The equivalent name of the enumerator, as specified in Godot.

If the value does not match one of the known enumerators, the empty string is returned.

ยงDeprecation

Design change is due to the fact that Godot enums may have multiple constants with the same ordinal value, and godot_name() cannot always return a unique name for it. So there are cases where this method returns unexpected results.

To keep the old โ€“ possibly incorrect โ€“ behavior, you can write the following function. However, it runs in linear rather than constant time (which is often OK, given that there are very few constants per enum).

use godot::obj::EngineEnum;

fn godot_name<T: EngineEnum + Eq + PartialEq + 'static>(value: T) -> &'static str {
    T::all_constants()
        .iter()
        .find(|c| c.value() == value)
        .map(|c| c.godot_name())
        .unwrap_or("") // Previous behavior.
}
Source

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());
}
Source

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ยง

Source

fn from_ord(ord: i32) -> Self

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.

Implementorsยง

Sourceยง

impl EngineEnum for Corner

Sourceยง

impl EngineEnum for EulerOrder

Sourceยง

impl EngineEnum for Side

Sourceยง

impl EngineEnum for ClockDirection

Sourceยง

impl EngineEnum for Orientation

Sourceยง

impl EngineEnum for VariantOperator

Sourceยง

impl EngineEnum for VariantType

Sourceยง

impl EngineEnum for ClipChildrenMode

Sourceยง

impl EngineEnum for TextureFilter

Sourceยง

impl EngineEnum for TextureRepeat

Sourceยง

impl EngineEnum for ApiType

Sourceยง

impl EngineEnum for AfterGuiInput

Sourceยง

impl EngineEnum for CustomControlContainer

Sourceยง

impl EngineEnum for DockSlot

Sourceยง

impl EngineEnum for CompressionMode

Sourceยง

impl EngineEnum for ModeFlags

Sourceยง

impl EngineEnum for Result

Sourceยง

impl EngineEnum for CursorShape

Sourceยง

impl EngineEnum for MouseMode

Sourceยง

impl EngineEnum for godot_core::classes::mesh::ArrayCustomFormat

Sourceยง

impl EngineEnum for godot_core::classes::mesh::ArrayType

Sourceยง

impl EngineEnum for godot_core::classes::mesh::BlendShapeMode

Sourceยง

impl EngineEnum for godot_core::classes::mesh::PrimitiveType

Sourceยง

impl EngineEnum for AutoTranslateMode

Sourceยง

impl EngineEnum for DuplicateFlags

Sourceยง

impl EngineEnum for InternalMode

Sourceยง

impl EngineEnum for PhysicsInterpolationMode

Sourceยง

impl EngineEnum for ProcessMode

Sourceยง

impl EngineEnum for ProcessThreadGroup

Sourceยง

impl EngineEnum for RotationEditMode

Sourceยง

impl EngineEnum for RenderingDriver

Sourceยง

impl EngineEnum for StdHandleType

Sourceยง

impl EngineEnum for SystemDir

Sourceยง

impl EngineEnum for GenEditState

Sourceยง

impl EngineEnum for godot_core::classes::rendering_server::ArrayCustomFormat

Sourceยง

impl EngineEnum for godot_core::classes::rendering_server::ArrayType

Sourceยง

impl EngineEnum for BakeChannels

Sourceยง

impl EngineEnum for godot_core::classes::rendering_server::BlendShapeMode

Sourceยง

impl EngineEnum for CanvasGroupMode

Sourceยง

impl EngineEnum for CanvasItemTextureFilter

Sourceยง

impl EngineEnum for CanvasItemTextureRepeat

Sourceยง

impl EngineEnum for CanvasLightBlendMode

Sourceยง

impl EngineEnum for CanvasLightMode

Sourceยง

impl EngineEnum for CanvasLightShadowFilter

Sourceยง

impl EngineEnum for CanvasOccluderPolygonCullMode

Sourceยง

impl EngineEnum for CanvasTextureChannel

Sourceยง

impl EngineEnum for CompositorEffectCallbackType

Sourceยง

impl EngineEnum for CompositorEffectFlags

Sourceยง

impl EngineEnum for CubeMapLayer

Sourceยง

impl EngineEnum for DecalFilter

Sourceยง

impl EngineEnum for DecalTexture

Sourceยง

impl EngineEnum for DofBlurQuality

Sourceยง

impl EngineEnum for DofBokehShape

Sourceยง

impl EngineEnum for EnvironmentAmbientSource

Sourceยง

impl EngineEnum for EnvironmentBg

Sourceยง

impl EngineEnum for EnvironmentFogMode

Sourceยง

impl EngineEnum for EnvironmentGlowBlendMode

Sourceยง

impl EngineEnum for EnvironmentReflectionSource

Sourceยง

impl EngineEnum for EnvironmentSdfgiFramesToConverge

Sourceยง

impl EngineEnum for EnvironmentSdfgiFramesToUpdateLight

Sourceยง

impl EngineEnum for EnvironmentSdfgiRayCount

Sourceยง

impl EngineEnum for EnvironmentSdfgiYScale

Sourceยง

impl EngineEnum for EnvironmentSsaoQuality

Sourceยง

impl EngineEnum for EnvironmentSsilQuality

Sourceยง

impl EngineEnum for EnvironmentSsrRoughnessQuality

Sourceยง

impl EngineEnum for EnvironmentToneMapper

Sourceยง

impl EngineEnum for Features

Sourceยง

impl EngineEnum for FogVolumeShape

Sourceยง

impl EngineEnum for GlobalShaderParameterType

Sourceยง

impl EngineEnum for InstanceFlags

Sourceยง

impl EngineEnum for InstanceType

Sourceยง

impl EngineEnum for LightBakeMode

Sourceยง

impl EngineEnum for LightDirectionalShadowMode

Sourceยง

impl EngineEnum for LightDirectionalSkyMode

Sourceยง

impl EngineEnum for LightOmniShadowMode

Sourceยง

impl EngineEnum for LightParam

Sourceยง

impl EngineEnum for LightProjectorFilter

Sourceยง

impl EngineEnum for LightType

Sourceยง

impl EngineEnum for MultimeshPhysicsInterpolationQuality

Sourceยง

impl EngineEnum for MultimeshTransformFormat

Sourceยง

impl EngineEnum for NinePatchAxisMode

Sourceยง

impl EngineEnum for ParticlesCollisionHeightfieldResolution

Sourceยง

impl EngineEnum for ParticlesCollisionType

Sourceยง

impl EngineEnum for ParticlesDrawOrder

Sourceยง

impl EngineEnum for ParticlesMode

Sourceยง

impl EngineEnum for ParticlesTransformAlign

Sourceยง

impl EngineEnum for PipelineSource

Sourceยง

impl EngineEnum for godot_core::classes::rendering_server::PrimitiveType

Sourceยง

impl EngineEnum for ReflectionProbeAmbientMode

Sourceยง

impl EngineEnum for ReflectionProbeUpdateMode

Sourceยง

impl EngineEnum for RenderingInfo

Sourceยง

impl EngineEnum for ShaderMode

Sourceยง

impl EngineEnum for ShadowCastingSetting

Sourceยง

impl EngineEnum for ShadowQuality

Sourceยง

impl EngineEnum for SkyMode

Sourceยง

impl EngineEnum for SubSurfaceScatteringQuality

Sourceยง

impl EngineEnum for TextureLayeredType

Sourceยง

impl EngineEnum for TextureType

Sourceยง

impl EngineEnum for ViewportAnisotropicFiltering

Sourceยง

impl EngineEnum for ViewportClearMode

Sourceยง

impl EngineEnum for ViewportDebugDraw

Sourceยง

impl EngineEnum for ViewportEnvironmentMode

Sourceยง

impl EngineEnum for ViewportMsaa

Sourceยง

impl EngineEnum for ViewportOcclusionCullingBuildQuality

Sourceยง

impl EngineEnum for ViewportRenderInfo

Sourceยง

impl EngineEnum for ViewportRenderInfoType

Sourceยง

impl EngineEnum for ViewportScaling3DMode

Sourceยง

impl EngineEnum for ViewportScreenSpaceAa

Sourceยง

impl EngineEnum for ViewportSdfOversize

Sourceยง

impl EngineEnum for ViewportSdfScale

Sourceยง

impl EngineEnum for ViewportUpdateMode

Sourceยง

impl EngineEnum for ViewportVrsMode

Sourceยง

impl EngineEnum for ViewportVrsUpdateMode

Sourceยง

impl EngineEnum for VisibilityRangeFadeMode

Sourceยง

impl EngineEnum for VoxelGiQuality

Sourceยง

impl EngineEnum for godot_core::classes::resource_format_loader::CacheMode

Sourceยง

impl EngineEnum for godot_core::classes::resource_loader::CacheMode

Sourceยง

impl EngineEnum for ThreadLoadStatus

Sourceยง

impl EngineEnum for GroupCallFlags

Sourceยง

impl EngineEnum for ScriptNameCasing

Sourceยง

impl EngineEnum for CodeCompletionKind

Sourceยง

impl EngineEnum for CodeCompletionLocation

Sourceยง

impl EngineEnum for LookupResultType

Sourceยง

impl EngineEnum for Month

Sourceยง

impl EngineEnum for Weekday

Sourceยง

impl EngineEnum for AnisotropicFiltering

Sourceยง

impl EngineEnum for DebugDraw

Sourceยง

impl EngineEnum for DefaultCanvasItemTextureFilter

Sourceยง

impl EngineEnum for DefaultCanvasItemTextureRepeat

Sourceยง

impl EngineEnum for Msaa

Sourceยง

impl EngineEnum for PositionalShadowAtlasQuadrantSubdiv

Sourceยง

impl EngineEnum for RenderInfo

Sourceยง

impl EngineEnum for RenderInfoType

Sourceยง

impl EngineEnum for Scaling3DMode

Sourceยง

impl EngineEnum for ScreenSpaceAa

Sourceยง

impl EngineEnum for SdfOversize

Sourceยง

impl EngineEnum for SdfScale

Sourceยง

impl EngineEnum for VrsMode

Sourceยง

impl EngineEnum for VrsUpdateMode

Sourceยง

impl EngineEnum for ContentScaleAspect

Sourceยง

impl EngineEnum for ContentScaleMode

Sourceยง

impl EngineEnum for ContentScaleStretch

Sourceยง

impl EngineEnum for Flags

Sourceยง

impl EngineEnum for LayoutDirection

Sourceยง

impl EngineEnum for Mode

Sourceยง

impl EngineEnum for WindowInitialPosition

Sourceยง

impl EngineEnum for Error

Sourceยง

impl EngineEnum for HorizontalAlignment

Sourceยง

impl EngineEnum for InlineAlignment

Sourceยง

impl EngineEnum for JoyAxis

Sourceยง

impl EngineEnum for JoyButton

Sourceยง

impl EngineEnum for Key

Sourceยง

impl EngineEnum for KeyLocation

Sourceยง

impl EngineEnum for MidiMessage

Sourceยง

impl EngineEnum for MouseButton

Sourceยง

impl EngineEnum for PropertyHint

Sourceยง

impl EngineEnum for VerticalAlignment