Best-effort checks for Array<Integer>
conversions; fix Debug
for variants containing typed arrays
#853
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.
Addresses part of #727: the
Variant
Debug
impl no longer panics.However, conversions from
Array<T>
toVariantArray
are still not possible, and need more design (OutArray
PR #806).Closes #805.
I decided to not forbid
Array
with element typesu8
,i8
,u16
,i16
,u32
,i32
andf32
, for the following reasons:Array
is a general-purpose sequential data structure with focus on versatility/convenience. It's not particularly fast for small elements due to itsVariant
storage and conversions, but it supports the widest range of element types. The integer types fit somewhat naturally.i64
(a not very natural type in everyday gamedev) would make a lot of code more tedious. It's already something I really dislike aboutf64
, and I don't want to proliferate this practice.Array<i16>
etc. is exposing data from Rust to GDScript, e.g. returning from#[func]
or as a#[var]
property. If such an integer type is chosen in place ofi64
, that's usually because the developer knows the domain of the possible values, and the risk of inputing too big numbers is limited.i64
integer conversions. I consider justifiable because a) arrays are often small and/or sequential iteration is fast, b) performance is already bad forArray
and people who care use packed arrays, c) it's turned off in Release mode. It's also a no-op for all other array element types. This check is best-effort, so it won't catch all scenarios (like appending from GDScript).i64
andf64
. This also means no runtime checks.Furthermore, godot-cpp also allows
Array
with these element types. They go even further and enableuint64_t
, something we don't do.