Module godot_core::builtin

source ·
Expand description

Built-in types like Vector2, GString and Variant.

§Background on the design of vector algebra types

The basic vector algebra types like Vector2, Matrix4 and Quaternion are re-implemented here, with an API similar to that in the Godot engine itself. There are other approaches, but they all have their disadvantages:

  • We could invoke API methods from the engine. The implementations could be generated, but it is slower and prevents inlining.

  • We could re-export types from an existing vector algebra crate, like glam. This removes the duplication, but it would create a strong dependency on a volatile API outside our control. The gdnative crate started out this way, using types from euclid, but found it impractical. Moreover, the API would not match Godot’s own, which would make porting from GDScript (slightly) harder.

  • We could opaquely wrap types from an existing vector algebra crate. This protects users of gdextension from changes in the wrapped crate. However, direct field access using .x, .y, .z is no longer possible. Instead of v.y += a; you would have to write v.set_y(v.get_y() + a);. (A union could be used to add these fields in the public API, but would make every field access unsafe, which is also not great.)

  • We could re-export types from the mint crate, which was explicitly designed to solve this problem. However, it falls short because operator overloading would become impossible.

Re-exports§

  • pub use __prelude_reexport::*;

Modules§

  • Iterator types for arrays and dictionaries.
  • Math-related functions and traits like ApproxEq.
  • Specialized types related to Godot’s various string implementations.

Macros§

  • Constructs [Array] literals, similar to Rust’s standard vec! macro.
  • Constructs [Dictionary] literals, close to Godot’s own syntax.
  • A macro to coerce float-literals into the [real] type.
  • Array of reals.
  • Constructs [VariantArray] literals, similar to Rust’s standard vec! macro.

Structs§

Enums§

  • This enum is exhaustive; you should not expect future Godot versions to add new enumerators.
  • This enum is exhaustive; you should not expect future Godot versions to add new enumerators.
  • This enum is exhaustive; you should not expect future Godot versions to add new enumerators.