Skip to content

Commit 3c43cf2

Browse files
committed
Documentation around meta and its argument conversions
1 parent b36fd0a commit 3c43cf2

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

godot-core/src/meta/args/as_arg.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ use std::ffi::CStr;
1919
/// - `&T` for by-ref builtins: `GString`, `Array`, `Dictionary`, `Packed*Array`, `Variant`...
2020
/// - `&str`, `&String` additionally for string types `GString`, `StringName`, `NodePath`.
2121
///
22+
/// See also the [`AsObjectArg`][crate::meta::AsObjectArg] trait which is specialized for object arguments. It may be merged with `AsArg`
23+
/// in the future.
24+
///
2225
/// # Pass by value
2326
/// Implicitly converting from `T` for by-ref builtins is explicitly not supported. This emphasizes that there is no need to consume the object,
2427
/// thus discourages unnecessary cloning.

godot-core/src/meta/args/object_arg.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use std::ptr;
2020
/// - [`Option<&Gd<T>>`][Option], to pass optional objects. `None` is mapped to a null argument.
2121
/// - [`Gd::null_arg()`], to pass `null` arguments without using `Option`.
2222
///
23+
/// Note that [`AsObjectArg`] is very similar to the more general [`AsArg`][crate::meta::AsArg] trait. The two may be merged in the future.
24+
///
2325
/// # Nullability
2426
/// <div class="warning">
2527
/// The GDExtension API does not inform about nullability of its function parameters. It is up to you to verify that the arguments you pass

godot-core/src/meta/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8-
//! Meta-information about variant types, properties and class names.
8+
//! Meta-information about Godot types, their properties and conversions between them.
99
//!
1010
//! # Conversions between types
1111
//!
@@ -33,6 +33,15 @@
3333
//! Godot classes exist in a hierarchy. In OOP, it is usually possible to represent pointers to derived objects as pointer to their bases.
3434
//! For conversions between base and derived class objects, you can use `Gd` methods [`cast()`][crate::obj::Gd::cast],
3535
//! [`try_cast()`][crate::obj::Gd::try_cast] and [`upcast()`][crate::obj::Gd::upcast]. Upcasts are infallible.
36+
//!
37+
//! ## Argument conversions
38+
//!
39+
//! Rust does not support implicit conversions, however it has something very close: the `impl Into<T>` idiom, which can be used to convert
40+
//! "T-compatible" arguments into `T`. This library specializes this idea with two traits:
41+
//!
42+
//! - [`AsArg<T>`] allows argument conversions from arguments into `T`. This is most interesting in the context of strings (so you can pass
43+
//! `&str` to a function expecting `GString`), but is generic to support e.g. array insertion.
44+
//! - [`AsObjectArg<T>`] is a more specialized version of `AsArg` that is used for object arguments, i.e. `Gd<T>`.
3645
3746
mod args;
3847
mod array_type_info;

godot/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
//! * [`register`], used to register **your own** Rust symbols (classes, methods, constants etc.) with Godot.
3434
//! * [`obj`], everything related to handling Godot objects, such as the `Gd<T>` type.
3535
//! * [`tools`], higher-level utilities that extend the generated code, e.g. `load<T>()`.
36+
//! * [`meta`], fundamental information about types, properties and conversions.
37+
//! * [`init`], entry point and global library configuration.
3638
//!
3739
//! The [`prelude`] contains often-imported symbols; feel free to `use godot::prelude::*` in your code.
3840
//! <br><br>

0 commit comments

Comments
 (0)