Skip to main content

GodotShape

Enum GodotShape 

#[non_exhaustive]
pub enum GodotShape { Variant, Builtin { variant_type: VariantType, }, Class { class_id: ClassId, heritage: ClassHeritage, }, TypedArray { element: GodotElementShape, }, TypedDictionary { key: GodotElementShape, value: GodotElementShape, }, Enum { variant_type: VariantType, enumerators: Cow<'static, [Enumerator]>, godot_name: Option<Cow<'static, str>>, is_bitfield: bool, }, Custom { variant_type: VariantType, var_hint: PropertyHintInfo, export_hint: PropertyHintInfo, class_name: Option<Cow<'static, str>>, usage_flags: PropertyUsageFlags, }, }
Expand description

The “shape” of a Godot type: whether it’s a builtin, a class, an enum/bitfield, etc.

Describes a static (compile-time) type as it should be registered with Godot; returned by GodotConvert::godot_shape(). This is distinct from runtime introspection APIs such AnyArray::element_type().

Usually you need to deal with GodotShape only if you define custom types through manual GodotConvert impls.

§Information provided by the shape

A shape description is used for three purposes:

§Property registration

During registration of class properties, the runtime resolves hints and usage flags from the shape:

  • For #[var], it calls var_hint() and uses NONE as base usage.
  • For #[export], it calls export_hint() and uses DEFAULT as base usage.
  • If the user specifies explicit overrides (e.g. #[var(hint = ...)] or #[export(range = ...)]), those replace hints from the shape.

The shape also contributes structural metadata – variant type, class name, and additional usage flags (via usage_flags()). These are combined with the hint and base usage into a PropertyInfo for the Godot FFI call.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Variant

The general Variant type. Can hold any Godot value.

Distinct from Builtin { variant_type: NIL }, which represents the () unit type (void in GDScript).

§

Builtin

A built-in Godot type (int, String, Vector3, PackedByteArray, etc.).

The variant type used here must match the one from GodotConvert::Via.

Packed arrays, untyped arrays and untyped dictionaries are also represented as Builtin.
Typed arrays, typed dictionaries, objects and variants have their own shape representation.

Fields

§variant_type: VariantType

Godot variant type (e.g. INT, FLOAT, STRING, VECTOR3, PACKED_BYTE_ARRAY). Never OBJECT.

§

Class

A Godot object type (Gd<T>, DynGd<T, D>, Option<Gd<T>>, OnReady<Gd<T>>, etc.).

Always has VariantType::OBJECT.

Fields

§class_id: ClassId

The Godot class of this object type (e.g. Node, Resource).

§heritage: ClassHeritage

Whether this inherits from Resource, Node, or other object class.

§

TypedArray

An Array<T> where T is not Variant.

Untyped arrays are represented as Builtin { variant_type: VariantType::ARRAY }.

Fields

§element: GodotElementShape

Shape of the array element type.

§

TypedDictionary

A Dictionary<K, V> where at least one of K, V is not Variant (Godot 4.4+).

Untyped dictionaries are represented as Builtin { variant_type: VariantType::DICTIONARY }.

Fields

§key: GodotElementShape

Shape of the dictionary key type.

§value: GodotElementShape

Shape of the dictionary value type.

§

Enum

An enum or bitfield type (engine-defined or user-defined).

Fields

§variant_type: VariantType

Godot variant type of the underlying representation (typically INT for int-backed enums, STRING for string-backed).

§enumerators: Cow<'static, [Enumerator]>

Display name and ordinal for each enumerator. Borrowed for compile-time data, Owned for dynamic enumerators.

§godot_name: Option<Cow<'static, str>>

Godot-qualified enum name. Some("Orientation") or Some("Node.ProcessMode") for engine enums; None for user enums.

When Some, the framework sets class_name + CLASS_IS_ENUM in PropertyInfo and uses NONE hint for #[var] (Godot resolves the enum from class_name). When None, uses ENUM/FLAGS hint with hint_string directly.

§is_bitfield: bool

Whether this is a bitfield:

  • true for bitfields (FLAGS hint, CLASS_IS_BITFIELD usage).
  • false for regular enums (ENUM hint, CLASS_IS_ENUM usage).
§

Custom

Fully custom property metadata. Use only when the type doesn’t fit any predefined shape

Fields

§variant_type: VariantType

Godot variant type.

§var_hint: PropertyHintInfo

Property hint info for #[var] context.

§export_hint: PropertyHintInfo

Property hint info for #[export] context.

§class_name: Option<Cow<'static, str>>

Stored as CowStr; converted to ClassId only at registration time to avoid eager global cache allocation.

§usage_flags: PropertyUsageFlags

Additional usage flags.

These are bit-ORed with the base usage, see to_var_property() and to_export_property().

Typically you can use NONE if the shape doesn’t need extra flags.

Implementations§

§

impl GodotShape

pub fn of_builtin<T>() -> GodotShape
where T: GodotConvert,

Creates GodotShape::Builtin for a type T directly representable as a Godot builtin, including packed arrays.

Returns either of:

  • Variant, if T is Variant.
  • GodotShape::Builtin { variant_type: ffi_variant_type::<T>().variant_as_nil() } for other builtins.

Do not use for objects, typed arrays/dictionaries or enums; those have their own shape variants.

pub fn variant_type(&self) -> VariantType

Returns the Godot VariantType for this shape.

pub fn var_hint(&self) -> PropertyHintInfo

Property hint for #[var] context.

pub fn export_hint(&self) -> PropertyHintInfo

Property hint for #[export] context.

For enums, always uses ENUM/FLAGS + hint_string (even engine enums need explicit hints for export).

pub fn usage_flags(&self) -> PropertyUsageFlags

Shape-specific usage flags for property registration.

These are combined with the base usage, which is NONE for #[var] and DEFAULT for #[export].

pub fn to_method_signature_property(&self, property_name: &str) -> PropertyInfo

Builds the low-level Godot property info for method parameter/return type registration.

Uses:

  • Hint and hint string: var_hint().
  • Usage: DEFAULT (required for method params; not shown in editor).

pub fn to_var_property(&self, property_name: &str) -> PropertyInfo

Builds the low-level Godot property info for #[var] context.

Uses:

  • Hint and hint string: var_hint().
  • Base usage: NONE, combined with specific usage_flags() from this shape. Property is accessible from GDScript, but not shown in editor or saved.

See also PropertyInfo::new_var().

pub fn to_export_property(&self, property_name: &str) -> PropertyInfo

Builds the low-level Godot property info for #[export] context.

Uses:

See also PropertyInfo::new_export().

Trait Implementations§

§

impl Clone for GodotShape

§

fn clone(&self) -> GodotShape

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for GodotShape

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.