Separate public and internal ToGodot + FromGodot traits
#1413
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduces new internal traits
EngineToGodot+EngineFromGodot. These are used by functions in generated code for engine APIs. Where available, they delegate toToGodot+FromGodottraits via blanket impl. In addition, they have implementations for types that make sense on an engine level, but not for user-defined#[func]functions orVariantconversions.This addresses multiple problems:
Type
u64currently implementsToGodot/FromGodotout of necessity:std::uint64_tand thus safe.#[func]interacts with GDScript, which does not have an unsigned 64-bit type. The current implementation panics, which is the only instance of such behavior in otherwise infallibleToGodot::to_godot(). Silently changing value would be even worse.impl To/FromGodot for u64.Similar: raw pointers like native-struct
*const AudioFrame, or*const c_voidused in virtual methods.#[func]. You can just do123.to_variant().to::<*mut Glyph>()and obtain a bad pointer.#[func]doesn't.impldocs forToGodotandFromGodot.There is currently a bug: API calls cause runtime panics for some
u64values.value > i64::MAX, theToGodotvalidation kicks in and causes panic.u64_fileaccess_roundtriptests that this works after the changes.Relatedly, bitfields are represented as
u64.EngineToGodottrait can handle this case without exposing error-prone conversions for public use.