Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Generics, Generated APIs, and Runtime Checks

Type designStatic engine relationshipsRevision 637cef7

Gd<T: GodotClass> statically carries the engine class. Bounds such as T: Inherits<Node> admit only operations valid for that class hierarchy. Associated types on GodotClass select Base, declaration domain, and memory strategy, allowing clone/drop behavior to differ for manually managed and reference-counted objects.

Conversion traits describe whether a Rust value travels by value or reference, its Godot Variant representation, and its low-level ABI layout. Generated methods use these traits rather than dynamically guessing signatures.

Procedural macros generate implementations for user-defined classes and methods; build-time code generation creates the enormous engine API. At runtime, registries erase class registration functions and Godot supplies untyped pointers. Exact generic types are recovered only after class, liveness, and borrow validation.

This is a boundary-heavy form of generics: the type system prevents invalid calls before FFI, while runtime checks defend facts controlled by C++ after compilation.