gdnative/
lib.rs

1//! # Rust bindings for the Godot game engine
2//!
3//! This crate contains high-level wrappers around the Godot game engine's GDNative API.
4//! Some of the types were automatically generated from the engine's JSON API description,
5//! and some other types are hand made wrappers around the core C types.
6//!
7//! ## Core types
8//!
9//! Wrappers for most core types expose safe Rust interfaces, and it's unnecessary
10//! to mind memory management most of the times. The exceptions are
11//! [`VariantArray`](core_types::VariantArray) and [`Dictionary`](core_types::Dictionary),
12//! internally reference-counted collections with _interior mutability_ in Rust parlance.
13//! These types are modelled using the _typestate_ pattern to enforce that the official
14//! [thread-safety guidelines][thread-safety]. For more information, read the type-level
15//! documentation for these types.
16//!
17//! Since it is easy to expect containers and other types to allocate a copy of their
18//! content when using the `Clone` trait, some types do not implement `Clone` and instead
19//! implement [`NewRef`](object::NewRef) which provides a `new_ref(&self) -> Self` method
20//! to create references to the same collection or object.
21//!
22//! ## Generated API types
23//!
24//! The [`api`] module contains high-level wrappers for all the API types generated from a
25//! JSON description of the API. The generated types are tied to a specific version, typically
26//! the latest Godot 3.x release (at the time of the godot-rust release).
27//! If you want to use the bindings with another version of the engine, read the notes on
28//! the `custom-godot` feature flag below.
29//!
30//! ### Memory management
31//!
32//! API types may be reference-counted or manually-managed. This is indicated by the
33//! `RefCounted` and `ManuallyManaged` marker traits.
34//!
35//! The API types can exist in three reference forms: bare, [`TRef`](object::TRef) and [`Ref`](object::Ref).
36//! Bare references to API types, like `&'a Node`, represent valid and safe references to Godot objects.
37//! As such, API methods may be called safely on them. `TRef` adds typestate tracking, which
38//! enable additional abilities like being able to be passed to the engine. `Ref`, or
39//! _persistent_ references, have `'static` lifetime, but are not always safe to use. For more
40//! information on how to use persistent references safely, see the [`object`] module documentation
41//! or the corresponding [book chapter][gdnative-overview].
42//!
43//! ## Feature flags
44//! All features are disabled by default.
45//!
46//! Functionality toggles:
47//!
48//! * **`async`**<br>
49//!   Activates async functionality, see [`tasks`] module for details.
50//!
51//! * **`serde`**<br>
52//!   Enable for `serde` support of several core types. See also [`Variant`](core_types::Variant).
53//!
54//! * **`inventory`**<br>
55//!   Enables automatic class registration via `inventory`.
56//!
57//!   **Attention:** Automatic registration is unsupported on some platforms, notably WASM. `inventory`
58//!   can still be used for iterative development if such platforms are targeted, in which case the
59//!   run-time diagnostic [`init::diagnostics::missing_manual_registration`] may be helpful.
60//!
61//!   Please refer to [the `rust-ctor` README][ctor-repo] for an up-to-date listing of platforms
62//!   that *do* support automatic registration.
63//!
64//! Bindings generation:
65//!
66//! * **`custom-godot`**<br>
67//!   When active, tries to locate a Godot executable on your system, in this order:
68//!   1. If a `GODOT_BIN` environment variable is defined, it will interpret it as a path to the binary
69//!      (not directory).
70//!   2. An executable called `godot`, accessible in your system's PATH, is used.
71//!   3. If neither of the above is found, an error is generated.
72//!
73//!   The symbols in [`api`] will be generated in a way compatible with that engine version.
74//!   This allows to use Godot versions older than the currently supported ones.
75//!
76//!   See [Custom Godot builds][custom-godot] for detailed instructions.
77//!
78//! * **`formatted`**<br>
79//!   Enable if the generated binding source code should be human-readable and split
80//!   into multiple files. This can also help IDEs that struggle with a single huge file.
81//!
82//! * **`ptrcall`**<br>
83//!   Enables the `ptrcall` convention for calling Godot API methods. This increases performance, at the
84//!   cost of forward binary compatibility with the engine. Binaries built with `ptrcall` enabled
85//!   **may exhibit undefined behavior** when loaded by a different version of Godot, even when there are
86//!   no breaking API changes as far as GDScript is concerned. Notably, the addition of new default
87//!   parameters breaks any code using `ptrcall`.
88//!
89//!   Cargo features are additive, and as such, it's only necessary to enable this feature for the final
90//!   `cdylib` crates, whenever desired.
91//!
92//! [thread-safety]: https://docs.godotengine.org/en/stable/tutorials/threads/thread_safe_apis.html
93//! [gdnative-overview]: https://godot-rust.github.io/book/gdnative-overview.html
94//! [custom-godot]: https://godot-rust.github.io/book/advanced-guides/custom-godot.html
95//! [ctor-repo]: https://github.com/mmastrac/rust-ctor
96//!
97//!
98
99#![doc(html_logo_url = "https://github.com/godot-rust/gdnative/raw/master/assets/godot-ferris.svg")]
100
101// Workaround (rustdoc 1.55):
102// Items, which are #[doc(hidden)] in their original crate and re-exported with a wildcard, lose
103// their hidden status. Re-exporting them manually and hiding the wildcard solves this.
104#[doc(inline)]
105pub use gdnative_core::{
106    core_types, derive, export, godot_dbg, godot_error, godot_print, godot_site, init, log, object,
107    profiler,
108};
109
110pub mod globalscope;
111
112// Implementation details (e.g. used by macros).
113// However, do not re-export macros (on crate level), thus no wildcard
114#[doc(hidden)]
115pub use gdnative_core::{libc, private, sys};
116
117/// Curated re-exports of common items.
118pub mod prelude;
119
120/// Bindings for the Godot Class API.
121#[doc(inline)]
122pub use gdnative_bindings as api;
123
124#[doc(inline)]
125#[cfg(feature = "async")]
126pub use gdnative_async as tasks;