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 registrations (
#[var]) so that Godot has static type information of your type.- See
to_var_property()andvar_hint().
- See
- Exported properties (
#[export]) so that properties show up correctly in the editor’s inspector UI.- See
to_export_property()andexport_hint().
- See
- Method signatures (
#[func]), so that Godot has the static type information for parameters and return values.
§Property registration
During registration of class properties, the runtime resolves hints and usage flags from the shape:
- For
#[var], it callsvar_hint()and usesNONEas base usage. - For
#[export], it callsexport_hint()and usesDEFAULTas 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
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: VariantTypeGodot 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
heritage: ClassHeritageWhether 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: GodotElementShapeShape 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: GodotElementShapeShape of the dictionary key type.
value: GodotElementShapeShape of the dictionary value type.
Enum
An enum or bitfield type (engine-defined or user-defined).
Fields
variant_type: VariantTypeGodot 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.
Custom
Fully custom property metadata. Use only when the type doesn’t fit any predefined shape
Fields
variant_type: VariantTypeGodot variant type.
var_hint: PropertyHintInfoProperty hint info for #[var] context.
export_hint: PropertyHintInfoProperty 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: PropertyUsageFlagsAdditional 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
impl GodotShape
pub fn of_builtin<T>() -> GodotShapewhere
T: GodotConvert,
pub fn of_builtin<T>() -> GodotShapewhere
T: GodotConvert,
Creates GodotShape::Builtin for a type T directly representable as a Godot builtin, including packed arrays.
Returns either of:
- Variant, if
TisVariant. 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
pub fn variant_type(&self) -> VariantType
Returns the Godot VariantType for this shape.
pub fn var_hint(&self) -> PropertyHintInfo
pub fn var_hint(&self) -> PropertyHintInfo
Property hint for #[var] context.
pub fn export_hint(&self) -> PropertyHintInfo
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
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
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
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 specificusage_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
pub fn to_export_property(&self, property_name: &str) -> PropertyInfo
Builds the low-level Godot property info for #[export] context.
Uses:
- Hint and hint string:
export_hint(). - Usage:
DEFAULT, combined with specificusage_flags()from this shape. Property is shown in editor and saved.
See also PropertyInfo::new_export().
Trait Implementations§
§impl Clone for GodotShape
impl Clone for GodotShape
§fn clone(&self) -> GodotShape
fn clone(&self) -> GodotShape
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more