Module meta

Module meta 

Expand description

Meta-information about Godot types, their properties and conversions between them.

§Conversions between types

§Godot representation

The library provides two traits FromGodot and ToGodot, which are used at the Rust <-> Godot boundary, both in user-defined functions (#[func]) and engine APIs (godot::classes module). Their to_godot() and from_godot() methods convert types from/to their closest possible Godot type (e.g. GString instead of Rust String). You usually don’t need to call these methods yourself, they are automatically invoked when passing objects to/from Godot.

Most often, the two traits appear in pairs, however there are cases where only one of the two is implemented. For example, &str implements ToGodot but not FromGodot. Additionally, GodotConvert acts as a supertrait of both FromGodot and ToGodot. Its sole purpose is to define the “closest possible Godot type” GodotConvert::Via.

For fallible conversions, you can use FromGodot::try_from_godot().

§Variants

ToGodot and FromGodot also implement a conversion to/from Variant, which is the most versatile Godot type. This conversion is available via to_variant() and from_variant() methods. These methods are also available directly on Variant itself, via to(), try_to() and from() functions.

§Class conversions

Godot classes exist in a hierarchy. In OOP, it is usually possible to represent pointers to derived objects as pointer to their bases. For conversions between base and derived class objects, you can use Gd methods cast(), try_cast() and upcast(). Upcasts are infallible.

§Argument conversions

Rust does not support implicit conversions, however it has something very close: the impl Into<T> idiom, which can be used to convert “T-compatible” arguments into T. This library specializes this idea with two traits:

  • AsArg<T> allows argument conversions from arguments into T. This is most interesting in the context of strings (so you can pass &str to a function expecting GString), but is generic to support object arguments like Gd<T> and array insertion.

Modules§

error
Errors in the gdext library.
inspect
Introspection metadata for Godot engine types.

Structs§

ClassId
Globally unique ID of a class registered with Godot.
ElementScript
Compact representation inside ElementType::ScriptClass.
MethodInfo
Describes a method in Godot.
PropertyHintInfo
Info needed by Godot, for how to export a type to the editor.
PropertyInfo
Describes a property in Godot.

Enums§

ByObject
Pass arguments to Godot by object pointer (for objects only).
ByOption
Pass optional arguments by returning Option<&T::Via>, allowing delegation to underlying type’s strategy.
ByRef
Pass arguments to Godot by reference.
ByValue
Pass arguments to Godot by value.
ElementType
Dynamic type information of Godot arrays and dictionaries.

Traits§

ArgPassing
Determines whether arguments are passed by value or by reference to Godot.
ArrayElement
Marker trait to identify types that can be stored in Array<T>.
AsArg
Implicit conversions for arguments passed to Godot APIs.
FromGodot
Defines the canonical conversion from Godot for a type.
GodotConvert
Indicates that a type can be passed to/from Godot, either directly or through an intermediate “via” type.
GodotType
Type that is directly representable in the engine.
InParamTuple
Represents a parameter list that is received from some external location (usually Godot).
OutParamTuple
Represents a parameter list that is used to call some external code.
PackedArrayElement
Marker trait to identify types that can be stored in PackedArray<T>.
ParamTuple
Represents a parameter list as Rust tuple where each tuple element is one parameter.
SignedRange
Trait supporting regular usize ranges, as well as negative indices.
ToGodot
Defines the canonical conversion to Godot for a type.
UniformObjectDeref
Unifies dereferencing of user and engine classes, as &T/&mut T and Gd<T>.

Functions§

owned_into_arg
Generic abstraction over T owned values that should be passed as AsArg<T>.
ref_to_arg
Generic abstraction over &T references that should be passed as AsArg<T>.
wrapped
Accepts negative bounds, interpreted relative to the end of the collection.

Type Aliases§

ClassNameDeprecated