|
4 | 4 | * file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +//! Rust bindings for GDExtension, the extension API of [Godot](https://godotengine.org/) 4. |
| 8 | +//! |
| 9 | +//! This documentation is a work in progress. |
| 10 | +//! |
| 11 | +//! # Kinds of types |
| 12 | +//! |
| 13 | +//! Godot is written in C++, which doesn't have the same strict guarantees about safety and |
| 14 | +//! mutability that Rust does. As a result, not everything in this crate will look and feel |
| 15 | +//! entirely "Rusty". We distinguish four different kinds of types: |
| 16 | +//! |
| 17 | +//! 1. **Value types**: `i64`, `f64`, and mathematical types like |
| 18 | +//! [`Vector2`][crate::builtin::Vector2] and [`Color`][crate::builtin::Color]. |
| 19 | +//! |
| 20 | +//! These are the simplest to understand and to work with. They implement `Clone` and often |
| 21 | +//! `Copy` as well. They are implemented with the same memory layout as their counterparts in |
| 22 | +//! Godot itself, and typically have public fields. <br><br> |
| 23 | +//! |
| 24 | +//! 2. **Copy-on-write types**: [`GodotString`][crate::builtin::GodotString], |
| 25 | +//! [`StringName`][crate::builtin::StringName], and `Packed*Array` types. |
| 26 | +//! |
| 27 | +//! These mostly act like value types, similar to Rust's own `Vec`. You can `Clone` them to get |
| 28 | +//! a full copy of the entire object, as you would expect. |
| 29 | +//! |
| 30 | +//! Under the hood in Godot, these types are implemented with copy-on-write, so that data can be |
| 31 | +//! shared until one of the copies needs to be modified. However, this performance optimization |
| 32 | +//! is entirely hidden from the API and you don't normally need to worry about it. <br><br> |
| 33 | +//! |
| 34 | +//! 3. **Reference-counted types**: [`Array`][crate::builtin::Array], |
| 35 | +//! [`Dictionary`][crate::builtin::Dictionary], and [`Gd<T>`][crate::obj::Gd] where `T` inherits |
| 36 | +//! from [`RefCounted`][crate::engine::RefCounted]. |
| 37 | +//! |
| 38 | +//! These types may share their underlying data between multiple instances: changes to one |
| 39 | +//! instance are visible in another. Think of them as `Rc<RefCell<...>>` but without any runtime |
| 40 | +//! borrow checking. |
| 41 | +//! |
| 42 | +//! Since there is no way to prevent or even detect this sharing from Rust, you need to be more |
| 43 | +//! careful when using such types. For example, when iterating over an `Array`, make sure that |
| 44 | +//! it isn't being modified at the same time through another reference. |
| 45 | +//! |
| 46 | +//! To avoid confusion these types don't implement `Clone`. You can use |
| 47 | +//! [`Share`][crate::obj::Share] to create a new reference to the same instance, and |
| 48 | +//! type-specific methods such as |
| 49 | +//! [`Array::duplicate_deep()`][crate::builtin::Array::duplicate_deep] to make actual |
| 50 | +//! copies. <br><br> |
| 51 | +//! |
| 52 | +//! 4. **Manually managed types**: [`Gd<T>`][crate::obj::Gd] where `T` inherits from |
| 53 | +//! [`Object`][crate::engine::Object] but not from [`RefCounted`][crate::engine::RefCounted]; |
| 54 | +//! most notably, this includes all `Node` classes. |
| 55 | +//! |
| 56 | +//! These also share data, but do not use reference counting to manage their memory. Instead, |
| 57 | +//! you must either hand over ownership to Godot (e.g. by adding a node to the scene tree) or |
| 58 | +//! free them manually using [`Gd::free()`][crate::obj::Gd::free]. <br><br> |
| 59 | +//! |
| 60 | +//! # Thread safety |
| 61 | +//! |
| 62 | +//! [Godot's own thread safety |
| 63 | +//! rules](https://docs.godotengine.org/en/latest/tutorials/performance/thread_safe_apis.html) |
| 64 | +//! apply. Types in this crate implement (or don't implement) `Send` and `Sync` wherever |
| 65 | +//! appropriate, but the Rust compiler cannot check what happens to an object through C++ or |
| 66 | +//! GDScript. |
| 67 | +//! |
| 68 | +//! As a rule of thumb, if you must use threading, prefer to use Rust threads instead of Godot |
| 69 | +//! threads. |
| 70 | +
|
7 | 71 | #[doc(inline)]
|
8 | 72 | pub use godot_core::{builtin, engine, log, obj, sys};
|
9 | 73 |
|
|
0 commit comments