Skip to content

Commit ee07cea

Browse files
authored
Merge pull request #1428 from godot-rust/qol/untyped-collection-rename
Rename untyped collections to `VarArray` + `VarDictionary`
2 parents 6eeb84e + 4cdf57c commit ee07cea

File tree

31 files changed

+219
-202
lines changed

31 files changed

+219
-202
lines changed

godot-codegen/src/conv/type_conversions.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ fn to_hardcoded_rust_ident(full_ty: &GodotTy) -> Option<&str> {
5353
// Others
5454
("bool", None) => "bool",
5555
("String", None) => "GString",
56-
("Array", None) => "VariantArray",
56+
("Array", None) => "VarArray",
57+
("Dictionary", None) => "VarDictionary",
5758

5859
// Types needed for native structures mapping
5960
("uint8_t", None) => "u8",
@@ -331,8 +332,8 @@ fn to_rust_expr_inner(expr: &str, ty: &RustTy, is_inner: bool) -> TokenStream {
331332
"true" => return quote! { true },
332333
"false" => return quote! { false },
333334
"[]" | "{}" if is_inner => return quote! {},
334-
"[]" => return quote! { Array::new() }, // VariantArray or Array<T>
335-
"{}" => return quote! { Dictionary::new() },
335+
"[]" => return quote! { Array::new() }, // VarArray or Array<T>
336+
"{}" => return quote! { VarDictionary::new() },
336337
"null" => {
337338
return match ty {
338339
RustTy::BuiltinIdent { ty: ident, .. } if ident == "Variant" => {
@@ -614,7 +615,7 @@ fn gdscript_to_rust_expr() {
614615
// Special literals
615616
("true", None, quote! { true }),
616617
("false", None, quote! { false }),
617-
("{}", None, quote! { Dictionary::new() }),
618+
("{}", None, quote! { VarDictionary::new() }),
618619
("[]", None, quote! { Array::new() }),
619620

620621
("null", ty_variant, quote! { Variant::nil() }),

godot-codegen/src/generator/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ fn method_safety_doc(class_name: &TyName, method: &BuiltinMethod) -> Option<Toke
211211
///
212212
/// In the current implementation, both cases will produce a panic rather than undefined behavior, but this should not be relied upon.
213213
});
214-
} else if &method.return_value().type_tokens().to_string() == "VariantArray" {
214+
} else if &method.return_value().type_tokens().to_string() == "VarArray" {
215215
return Some(quote! {
216216
/// # Safety
217217
///

godot-core/src/builtin/callable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{fmt, ptr};
1111
use godot_ffi as sys;
1212
use sys::{ffi_methods, ExtVariantType, GodotFfi};
1313

14-
use crate::builtin::{inner, GString, StringName, Variant, VariantArray};
14+
use crate::builtin::{inner, GString, StringName, VarArray, Variant};
1515
use crate::meta::{GodotType, ToGodot};
1616
use crate::obj::bounds::DynMemory;
1717
use crate::obj::{Bounds, Gd, GodotClass, InstanceId, Singleton};
@@ -381,14 +381,14 @@ impl Callable {
381381
/// - If called on an invalid Callable then no error is printed, and `NIL` is returned.
382382
///
383383
/// _Godot equivalent: `callv`_
384-
pub fn callv(&self, arguments: &VariantArray) -> Variant {
384+
pub fn callv(&self, arguments: &VarArray) -> Variant {
385385
self.as_inner().callv(arguments)
386386
}
387387

388388
/// Returns a copy of this Callable with one or more arguments bound, reading them from an array.
389389
///
390390
/// _Godot equivalent: `bindv`_
391-
pub fn bindv(&self, arguments: &VariantArray) -> Self {
391+
pub fn bindv(&self, arguments: &VarArray) -> Self {
392392
self.as_inner().bindv(arguments)
393393
}
394394

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::registry::property::{BuiltinExport, Export, Var};
3737
/// Godot's `Array` can be either typed or untyped.
3838
///
3939
/// An untyped array can contain any kind of [`Variant`], even different types in the same array.
40-
/// We represent this in Rust as `VariantArray`, which is just a type alias for `Array<Variant>`.
40+
/// We represent this in Rust as `VarArray`, which is just a type alias for `Array<Variant>`.
4141
///
4242
/// Godot also supports typed arrays, which are also just `Variant` arrays under the hood, but with
4343
/// runtime checks, so that no values of the wrong type are inserted into the array. We represent this as
@@ -93,8 +93,8 @@ use crate::registry::property::{BuiltinExport, Export, Var};
9393
///
9494
/// ```no_run
9595
/// # use godot::prelude::*;
96-
/// // VariantArray allows dynamic element types.
97-
/// let mut array = VariantArray::new();
96+
/// // VarArray allows dynamic element types.
97+
/// let mut array = VarArray::new();
9898
/// array.push(&10.to_variant());
9999
/// array.push(&"Hello".to_variant());
100100
///
@@ -191,11 +191,14 @@ impl<'a> std::ops::Deref for ImmutableInnerArray<'a> {
191191
}
192192
}
193193

194-
/// A Godot `Array` without an assigned type.
194+
#[deprecated = "Renamed to `VarArray`."]
195195
pub type VariantArray = Array<Variant>;
196196

197+
/// Untyped Godot `Array`.
198+
pub type VarArray = Array<Variant>;
199+
197200
// TODO check if these return a typed array
198-
impl_builtin_froms!(VariantArray;
201+
impl_builtin_froms!(VarArray;
199202
PackedByteArray => array_from_packed_byte_array,
200203
PackedColorArray => array_from_packed_color_array,
201204
PackedFloat32Array => array_from_packed_float32_array,
@@ -208,7 +211,7 @@ impl_builtin_froms!(VariantArray;
208211
);
209212

210213
#[cfg(since_api = "4.3")]
211-
impl_builtin_froms!(VariantArray;
214+
impl_builtin_froms!(VarArray;
212215
PackedVector4Array => array_from_packed_vector4_array,
213216
);
214217

@@ -521,7 +524,7 @@ impl<T: ArrayElement> Array<T> {
521524
self.balanced_ensure_mutable();
522525

523526
// SAFETY: `append_array` will only read values from `other`, and all types can be converted to `Variant`.
524-
let other: &VariantArray = unsafe { other.assume_type_ref::<Variant>() };
527+
let other: &VarArray = unsafe { other.assume_type_ref::<Variant>() };
525528

526529
// SAFETY: `append_array` will only write values gotten from `other` into `self`, and all values in `other` are guaranteed
527530
// to be of type `T`.
@@ -1124,7 +1127,7 @@ fn correct_variant_t() {
11241127
assert!(!Array::<i64>::has_variant_t());
11251128
}
11261129

1127-
impl VariantArray {
1130+
impl VarArray {
11281131
/// # Safety
11291132
/// - Variant must have type `VariantType::ARRAY`.
11301133
/// - Subsequent operations on this array must not rely on the type of the array.
@@ -1165,7 +1168,7 @@ unsafe impl<T: ArrayElement> GodotFfi for Array<T> {
11651168
}
11661169

11671170
// Only implement for untyped arrays; typed arrays cannot be nested in Godot.
1168-
impl ArrayElement for VariantArray {}
1171+
impl ArrayElement for VarArray {}
11691172

11701173
impl<T: ArrayElement> GodotConvert for Array<T> {
11711174
type Via = Self;
@@ -1271,7 +1274,7 @@ where
12711274
fn export_hint() -> PropertyHintInfo {
12721275
// If T == Variant, then we return "Array" builtin type hint.
12731276
if Self::has_variant_t() {
1274-
PropertyHintInfo::type_name::<VariantArray>()
1277+
PropertyHintInfo::type_name::<VarArray>()
12751278
} else {
12761279
PropertyHintInfo::export_array_element::<T>()
12771280
}
@@ -1598,14 +1601,14 @@ macro_rules! array {
15981601
};
15991602
}
16001603

1601-
/// Constructs [`VariantArray`] literals, similar to Rust's standard `vec!` macro.
1604+
/// Constructs [`VarArray`] literals, similar to Rust's standard `vec!` macro.
16021605
///
16031606
/// The type of the array elements is always [`Variant`].
16041607
///
16051608
/// # Example
16061609
/// ```no_run
16071610
/// # use godot::prelude::*;
1608-
/// let arr: VariantArray = varray![42_i64, "hello", true];
1611+
/// let arr: VarArray = varray![42_i64, "hello", true];
16091612
/// ```
16101613
///
16111614
/// # See also
@@ -1620,7 +1623,7 @@ macro_rules! varray {
16201623
($($elements:expr),* $(,)?) => {
16211624
{
16221625
use $crate::meta::ToGodot as _;
1623-
let mut array = $crate::builtin::VariantArray::default();
1626+
let mut array = $crate::builtin::VarArray::default();
16241627
$(
16251628
array.push(&$elements.to_variant());
16261629
)*
@@ -1668,7 +1671,6 @@ macro_rules! vslice {
16681671
($($elements:expr),* $(,)?) => {
16691672
{
16701673
use $crate::meta::ToGodot as _;
1671-
let mut array = $crate::builtin::VariantArray::default();
16721674
&[
16731675
$( $elements.to_variant(), )*
16741676
]

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

Lines changed: 3 additions & 3 deletions
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-
use crate::builtin::{to_usize, Array, Callable, Variant, VariantArray};
8+
use crate::builtin::{to_usize, Array, Callable, VarArray, Variant};
99
use crate::meta::{ArrayElement, AsArg};
1010
use crate::{meta, sys};
1111

@@ -59,7 +59,7 @@ impl<'a, T: ArrayElement> ArrayFunctionalOps<'a, T> {
5959
/// **Rust alternatives:** [`Iterator::map()`].
6060
///
6161
/// The callable has signature `fn(T) -> Variant`. Since the transformation can change the element type, this method returns
62-
/// a `VariantArray` (untyped array).
62+
/// a `VarArray` (untyped array).
6363
///
6464
/// # Example
6565
/// ```no_run
@@ -71,7 +71,7 @@ impl<'a, T: ArrayElement> ArrayFunctionalOps<'a, T> {
7171
/// assert_eq!(rounded, varray![1, 2, 2]);
7272
/// ```
7373
#[must_use]
74-
pub fn map(&self, callable: &Callable) -> VariantArray {
74+
pub fn map(&self, callable: &Callable) -> VarArray {
7575
// SAFETY: map() returns an untyped array.
7676
unsafe { self.array.as_inner().map(callable) }
7777
}

0 commit comments

Comments
 (0)