Skip to content

Commit 68b8a1f

Browse files
committed
Various doc improvements
1 parent a24cdc6 commit 68b8a1f

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

godot-core/src/meta/godot_convert/impls.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,6 @@ impl GodotType for u64 {
337337
impl_godot_scalar!(@shared_fns; i64, sys::GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_UINT64);
338338
}
339339

340-
/// Test that `u64` does not implement `ToGodot/FromGodot`.
341-
///
342-
/// The impls are not provided since `u64` is not a natively supported type in GDScript (e.g. cannot be stored in a variant without altering the
343-
/// value). So `#[func]` does not support it. However, engine APIs may still need it, so there is codegen/macro support.
344-
///
345-
/// ```compile_fail
346-
/// # use godot::prelude::*;
347-
/// let value: u64 = 42;
348-
/// let variant = value.to_variant(); // Error: u64 does not implement ToGodot
349-
/// ```
350340
impl GodotConvert for u64 {
351341
type Via = u64;
352342
}
@@ -468,6 +458,14 @@ impl<T: ArrayElement> ToGodot for &[T] {
468458
//
469459
// Sanity check: comment-out ::godot::meta::ensure_func_bounds in func.rs, the 3 latter #[func] ones should fail.
470460

461+
/// Test that `u64` cannot be converted to variant.
462+
///
463+
/// ```compile_fail
464+
/// # use godot::prelude::*;
465+
/// let variant = 100u64.to_variant(); // Error: u64 does not implement ToGodot
466+
/// ```
467+
fn __doctest_u64() {}
468+
471469
/// Test that `*mut i32` cannot be converted to variant.
472470
///
473471
/// ```compile_fail

godot-core/src/meta/godot_convert/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ use crate::meta::{ArgPassing, GodotType, ToArg};
2121
/// in Godot (without intermediate "via"). Every `GodotType` also implements `GodotConvert` with `Via = Self`.
2222
///
2323
/// Please read the [`godot::meta` module docs][crate::meta] for further information about conversions.
24+
///
25+
/// # u64
26+
/// The type `u64` is **not** supported by `ToGodot` and `FromGodot` traits. You can thus not pass it in `#[func]` parameters/return types.
27+
///
28+
/// The reason is that Godot's `Variant` type, and therefore also GDScript, only support _signed_ 64-bit integers (`i64`).
29+
/// Implicitly wrapping `u64` to `i64` would be surprising behavior, as the value could suddenly change for large numbers.
30+
/// As such, godot-rust leaves this decision to users: it's possible to define a newtype around `u64` with custom `ToGodot`/`FromGodot` impls.
2431
#[doc(alias = "via", alias = "transparent")]
2532
#[diagnostic::on_unimplemented(
2633
message = "`GodotConvert` is needed for `#[func]` parameters/returns, as well as `#[var]` and `#[export]` properties",

godot-core/src/meta/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub trait GodotType: GodotConvert<Via = Self> + sealed::Sealed + Sized + 'static
179179
/// best-effort checks to detect such errors, however they are expensive and not bullet-proof. If you need very rigid type safety, stick to
180180
/// `i64` and `f64`. The other types however can be extremely convenient and work well, as long as you are aware of the limitations.
181181
///
182-
/// `u64` is entirely unsupported since it cannot be safely stored inside a `Variant`.
182+
/// `u64` is [entirely unsupported](trait.GodotConvert.html#u64).
183183
///
184184
/// Also, keep in mind that Godot uses `Variant` for each element. If performance matters and you have small element types such as `u8`,
185185
/// consider using packed arrays (e.g. `PackedByteArray`) instead.

godot-core/src/obj/script.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<T: ScriptInstance> Drop for ScriptInstanceData<T> {
234234
}
235235
}
236236

237-
/// Creates a new from a type that implements [`ScriptInstance`].
237+
/// Creates a raw pointer to a Godot script instance, from a Rust [`ScriptInstance`] object.
238238
///
239239
/// See [`ScriptInstance`] for usage. Discarding the resulting value will result in a memory leak.
240240
///
@@ -246,7 +246,7 @@ impl<T: ScriptInstance> Drop for ScriptInstanceData<T> {
246246
pub unsafe fn create_script_instance<T: ScriptInstance>(
247247
rust_instance: T,
248248
for_object: Gd<T::Base>,
249-
) -> crate::meta::RawPtr<*mut c_void> {
249+
) -> RawPtr<*mut c_void> {
250250
// Field grouping matches C header.
251251
let gd_instance = ScriptInstanceInfo {
252252
set_func: Some(script_instance_info::set_property_func::<T>),

0 commit comments

Comments
 (0)