Skip to content

Commit fb19420

Browse files
committed
Note about element type safety of Array<T>
1 parent c6b2357 commit fb19420

File tree

1 file changed

+16
-0
lines changed
  • godot-core/src/builtin/collections

1 file changed

+16
-0
lines changed

godot-core/src/builtin/collections/array.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ use sys::{ffi_methods, interface_fn, GodotFfi};
109109
/// compiler will enforce this as long as you use only Rust threads, but it cannot protect against
110110
/// concurrent modification on other threads (e.g. created through GDScript).
111111
///
112+
/// # Element type safety
113+
///
114+
/// We provide a richer set of element types than Godot, for convenience and stronger invariants in your _Rust_ code.
115+
/// This, however, means that the Godot representation of such arrays is not capable of incorporating the additional "Rust-side" information.
116+
/// This can lead to situations where GDScript code or the editor UI can insert values that do not fulfill the Rust-side invariants.
117+
/// The library offers some best-effort protection in Debug mode, but certain errors may only occur on element access, in the form of panics.
118+
///
119+
/// Concretely, the following types lose type information when passed to Godot. If you want 100% bullet-proof arrays, avoid those.
120+
/// - Non-`i64` integers: `i8`, `i16`, `i32`, `u8`, `u16`, `u32`. (`u64` is unsupported).
121+
/// - Non-`f64` floats: `f32`.
122+
/// - Non-null objects: [`Gd<T>`][crate::obj::Gd].
123+
/// Godot generally allows `null` in arrays due to default-constructability, e.g. when using `resize()`.
124+
/// The Godot-faithful (but less convenient) alternative is to use `Option<Gd<T>>` element types.
125+
/// - Objects with dyn-trait association: [`DynGd<T, D>`][crate::obj::DynGd].
126+
/// Godot doesn't know Rust traits and will only see the `T` part.
127+
///
112128
/// # Godot docs
113129
///
114130
/// [`Array[T]` (stable)](https://docs.godotengine.org/en/stable/classes/class_array.html)

0 commit comments

Comments
 (0)