From 719d06b43ca1efc0cf1ec88c418faa3a5c456d4f Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Tue, 7 Mar 2023 13:04:52 +0100 Subject: [PATCH] Rename Array -> VariantArray, TypedArray -> Array --- godot-codegen/src/class_generator.rs | 2 +- godot-codegen/src/util.rs | 9 ++- godot-core/src/builtin/array.rs | 106 ++++++++++++------------- godot-core/src/builtin/dictionary.rs | 12 +-- godot-core/src/builtin/mod.rs | 2 +- godot-core/src/builtin/packed_array.rs | 2 +- itest/rust/src/array_test.rs | 43 +++++----- itest/rust/src/builtin_test.rs | 2 +- itest/rust/src/runner.rs | 6 +- itest/rust/src/variant_test.rs | 9 ++- 10 files changed, 97 insertions(+), 96 deletions(-) diff --git a/godot-codegen/src/class_generator.rs b/godot-codegen/src/class_generator.rs index d3efddb18..b1ce37f02 100644 --- a/godot-codegen/src/class_generator.rs +++ b/godot-codegen/src/class_generator.rs @@ -431,7 +431,7 @@ fn make_enums(enums: &Option>, _class_name: &TyName, _ctx: &Context) - fn make_special_builtin_methods(class_name: &TyName, _ctx: &Context) -> TokenStream { if class_name.godot_ty == "Array" { quote! { - pub fn from_outer_typed(outer: &TypedArray) -> Self + pub fn from_outer_typed(outer: &Array) -> Self where T: crate::builtin::meta::VariantMetadata { Self { diff --git a/godot-codegen/src/util.rs b/godot-codegen/src/util.rs index 9cb15e224..e599e170e 100644 --- a/godot-codegen/src/util.rs +++ b/godot-codegen/src/util.rs @@ -177,10 +177,11 @@ fn to_hardcoded_rust_type(ty: &str) -> Option<&str> { "int" => "i64", "float" => "f64", "String" => "GodotString", + "Array" => "VariantArray", //"enum::Error" => "GodotError", "enum::Variant.Type" => "VariantType", - "enum::Variant.Operator" => "VariantOperator", // currently not used, but future-proof - "enum::Vector3.Axis" => "Vector3Axis", // TODO automate this + "enum::Variant.Operator" => "VariantOperator", + "enum::Vector3.Axis" => "Vector3Axis", _ => return None, }; Some(result) @@ -251,10 +252,10 @@ fn to_rust_type_uncached(ty: &str, ctx: &mut Context) -> RustTy { let rust_elem_ty = to_rust_type(elem_ty, ctx); return if ctx.is_builtin(elem_ty) { - RustTy::BuiltinArray(quote! { TypedArray<#rust_elem_ty> }) + RustTy::BuiltinArray(quote! { Array<#rust_elem_ty> }) } else { RustTy::EngineArray { - tokens: quote! { TypedArray<#rust_elem_ty> }, + tokens: quote! { Array<#rust_elem_ty> }, elem_class: elem_ty.to_string(), } }; diff --git a/godot-core/src/builtin/array.rs b/godot-core/src/builtin/array.rs index a5e7ef04a..83c90e811 100644 --- a/godot-core/src/builtin/array.rs +++ b/godot-core/src/builtin/array.rs @@ -30,7 +30,7 @@ use sys::{ffi_methods, interface_fn, GodotFfi}; /// /// # Reference semantics /// -/// Like in GDScript, `TypedArray` acts as a reference type: multiple `TypedArray` instances may +/// Like in GDScript, `Array` acts as a reference type: multiple `Array` instances may /// refer to the same underlying array, and changes to one are visible in the other. /// /// To create a copy that shares data with the original array, use [`Share::share()`]. If you want @@ -38,7 +38,7 @@ use sys::{ffi_methods, interface_fn, GodotFfi}; /// /// # Thread safety /// -/// Usage is safe if the `TypedArray` is used on a single thread only. Concurrent reads on +/// Usage is safe if the `Array` is used on a single thread only. Concurrent reads on /// different threads are also safe, but any writes must be externally synchronized. The Rust /// compiler will enforce this as long as you use only Rust threads, but it cannot protect against /// concurrent modification on other threads (e.g. created through GDScript). @@ -47,16 +47,16 @@ use sys::{ffi_methods, interface_fn, GodotFfi}; // trait, whose `from_sys_init()` requires `Default`, which is only implemented for `T: // VariantMetadata`. Whew. This could be fixed by splitting up `GodotFfi` if desired. #[repr(C)] -pub struct TypedArray { +pub struct Array { opaque: sys::types::OpaqueArray, _phantom: PhantomData, } /// A Godot `Array` without an assigned type. -pub type Array = TypedArray; +pub type VariantArray = Array; // TODO check if these return a typed array -impl_builtin_froms!(Array; +impl_builtin_froms!(VariantArray; PackedByteArray => array_from_packed_byte_array, PackedColorArray => array_from_packed_color_array, PackedFloat32Array => array_from_packed_float32_array, @@ -68,7 +68,7 @@ impl_builtin_froms!(Array; PackedVector3Array => array_from_packed_vector3_array, ); -impl TypedArray { +impl Array { fn from_opaque(opaque: sys::types::OpaqueArray) -> Self { // Note: type is not yet checked at this point, because array has not yet been initialized! Self { @@ -210,25 +210,25 @@ impl TypedArray { /// from variants may fail. /// In the current implementation, both cases will produce a panic rather than undefined /// behavior, but this should not be relied upon. - unsafe fn assume_type(self) -> TypedArray { + unsafe fn assume_type(self) -> Array { // SAFETY: The memory layout of `TypedArray` does not depend on `T`. unsafe { std::mem::transmute(self) } } } -impl TypedArray { - /// Constructs an empty `TypedArray`. +impl Array { + /// Constructs an empty `Array`. pub fn new() -> Self { Self::default() } /// Returns a shallow copy of the array. All array elements are copied, but any reference types - /// (such as `TypedArray`, `Dictionary` and `Object`) will still refer to the same value. + /// (such as `Array`, `Dictionary` and `Object`) will still refer to the same value. /// /// To create a deep copy, use [`duplicate_deep()`] instead. To create a new reference to the /// same array data, use [`share()`]. pub fn duplicate_shallow(&self) -> Self { - let duplicate: Array = self.as_inner().duplicate(false); + let duplicate: VariantArray = self.as_inner().duplicate(false); // SAFETY: duplicate() returns a typed array with the same type as Self unsafe { duplicate.assume_type() } } @@ -240,13 +240,13 @@ impl TypedArray { /// To create a shallow copy, use [`duplicate_shallow()`] instead. To create a new reference to /// the same array data, use [`share()`]. pub fn duplicate_deep(&self) -> Self { - let duplicate: Array = self.as_inner().duplicate(true); + let duplicate: VariantArray = self.as_inner().duplicate(true); // SAFETY: duplicate() returns a typed array with the same type as Self unsafe { duplicate.assume_type() } } - /// Returns a slice of the `TypedArray`, from `begin` (inclusive) to `end` (exclusive), as a - /// new `TypedArray`. + /// Returns a slice of the `Array`, from `begin` (inclusive) to `end` (exclusive), as a + /// new `Array`. /// /// The values of `begin` and `end` will be clamped to the array size. /// @@ -254,15 +254,15 @@ impl TypedArray { /// in which case `begin` must be higher than `end`. For example, /// `TypedArray::from(&[0, 1, 2, 3, 4, 5]).slice(5, 1, -2)` returns `[5, 3]`. /// - /// Array elements are copied to the slice, but any reference types (such as `TypedArray`, + /// Array elements are copied to the slice, but any reference types (such as `Array`, /// `Dictionary` and `Object`) will still refer to the same value. To create a deep copy, use /// [`slice_deep()`] instead. pub fn slice_shallow(&self, begin: usize, end: usize, step: Option) -> Self { self.slice_impl(begin, end, step, false) } - /// Returns a slice of the `TypedArray`, from `begin` (inclusive) to `end` (exclusive), as a - /// new `TypedArray`. + /// Returns a slice of the `Array`, from `begin` (inclusive) to `end` (exclusive), as a + /// new `Array`. /// /// The values of `begin` and `end` will be clamped to the array size. /// @@ -285,7 +285,7 @@ impl TypedArray { let end = end.min(len); let step = step.unwrap_or(1); - let slice: Array = + let slice: VariantArray = self.as_inner() .slice(to_i64(begin), to_i64(end), step.try_into().unwrap(), deep); @@ -294,10 +294,10 @@ impl TypedArray { } /// Appends another array at the end of this array. Equivalent of `append_array` in GDScript. - pub fn extend_array(&mut self, other: TypedArray) { + pub fn extend_array(&mut self, other: Array) { // SAFETY: Read-only arrays are covariant: conversion to a variant array is fine as long as // we don't insert values into it afterwards, and `append_array()` doesn't do that. - let other: Array = unsafe { other.assume_type::() }; + let other: VariantArray = unsafe { other.assume_type::() }; self.as_inner().append_array(other); } @@ -344,12 +344,12 @@ impl TypedArray { } } -impl TypedArray { - /// Returns an iterator over the elements of the `TypedArray`. Note that this takes the array +impl Array { + /// Returns an iterator over the elements of the `Array`. Note that this takes the array /// by reference but returns its elements by value, since they are internally converted from /// `Variant`. /// - /// Notice that it's possible to modify the `TypedArray` through another reference while + /// Notice that it's possible to modify the `Array` through another reference while /// iterating over it. This will not result in unsoundness or crashes, but will cause the /// iterator to behave in an unspecified way. pub fn iter_shared(&self) -> Iter<'_, T> { @@ -447,7 +447,7 @@ impl TypedArray { } } -impl TypedArray { +impl Array { /// Finds the index of an existing value in a sorted array using binary search. Equivalent of /// `bsearch` in GDScript. /// @@ -566,7 +566,7 @@ impl TypedArray { // ... // } -impl GodotFfi for TypedArray { +impl GodotFfi for Array { ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque; .. } unsafe fn from_sys_init_default(init_fn: impl FnOnce(sys::GDExtensionTypePtr)) -> Self { @@ -576,7 +576,7 @@ impl GodotFfi for TypedArray { } } -impl fmt::Debug for TypedArray { +impl fmt::Debug for Array { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // Going through `Variant` because there doesn't seem to be a direct way. write!(f, "{:?}", self.to_variant().stringify()) @@ -586,9 +586,9 @@ impl fmt::Debug for TypedArray { /// Creates a new reference to the data in this array. Changes to the original array will be /// reflected in the copy and vice versa. /// -/// To create a (mostly) independent copy instead, see [`Array::duplicate_shallow()`] and -/// [`Array::duplicate_deep()`]. -impl Share for TypedArray { +/// To create a (mostly) independent copy instead, see [`VariantArray::duplicate_shallow()`] and +/// [`VariantArray::duplicate_deep()`]. +impl Share for Array { fn share(&self) -> Self { let array = unsafe { Self::from_sys_init(|self_ptr| { @@ -601,7 +601,7 @@ impl Share for TypedArray { } } -impl Default for TypedArray { +impl Default for Array { #[inline] fn default() -> Self { let mut array = unsafe { @@ -615,7 +615,7 @@ impl Default for TypedArray { } } -impl Drop for TypedArray { +impl Drop for Array { #[inline] fn drop(&mut self) { unsafe { @@ -625,7 +625,7 @@ impl Drop for TypedArray { } } -impl VariantMetadata for TypedArray { +impl VariantMetadata for Array { fn variant_type() -> VariantType { VariantType::Array } @@ -634,7 +634,7 @@ impl VariantMetadata for TypedArray { // ---------------------------------------------------------------------------------------------------------------------------------------------- // Conversion traits -impl ToVariant for TypedArray { +impl ToVariant for Array { fn to_variant(&self) -> Variant { unsafe { Variant::from_var_sys_init(|variant_ptr| { @@ -645,7 +645,7 @@ impl ToVariant for TypedArray { } } -impl FromVariant for TypedArray { +impl FromVariant for Array { fn try_from_variant(variant: &Variant) -> Result { if variant.get_type() != Self::variant_type() { return Err(VariantConversionError); @@ -661,15 +661,15 @@ impl FromVariant for TypedArray { } } -/// Creates a `TypedArray` from the given Rust array. -impl From<&[T; N]> for TypedArray { +/// Creates a `Array` from the given Rust array. +impl From<&[T; N]> for Array { fn from(arr: &[T; N]) -> Self { Self::from(&arr[..]) } } -/// Creates a `TypedArray` from the given slice. -impl From<&[T]> for TypedArray { +/// Creates a `Array` from the given slice. +impl From<&[T]> for Array { fn from(slice: &[T]) -> Self { let mut array = Self::new(); let len = slice.len(); @@ -688,8 +688,8 @@ impl From<&[T]> for TypedArray { } } -/// Creates a `TypedArray` from an iterator. -impl FromIterator for TypedArray { +/// Creates a `Array` from an iterator. +impl FromIterator for Array { fn from_iter>(iter: I) -> Self { let mut array = Self::new(); array.extend(iter); @@ -697,8 +697,8 @@ impl FromIterator for TypedArray { } } -/// Extends a `TypedArray` with the contents of an iterator. -impl Extend for TypedArray { +/// Extends a `Array` with the contents of an iterator. +impl Extend for Array { fn extend>(&mut self, iter: I) { // Unfortunately the GDExtension API does not offer the equivalent of `Vec::reserve`. // Otherwise we could use it to pre-allocate based on `iter.size_hint()`. @@ -712,8 +712,8 @@ impl Extend for TypedArray { } /// Converts this array to a strongly typed Rust vector. -impl From<&TypedArray> for Vec { - fn from(array: &TypedArray) -> Vec { +impl From<&Array> for Vec { + fn from(array: &Array) -> Vec { let len = array.len(); let mut vec = Vec::with_capacity(len); let ptr = array.ptr(0); @@ -731,7 +731,7 @@ impl From<&TypedArray> for Vec { // ---------------------------------------------------------------------------------------------------------------------------------------------- pub struct Iter<'a, T: VariantMetadata> { - array: &'a TypedArray, + array: &'a Array, next_idx: usize, } @@ -755,7 +755,7 @@ impl<'a, T: VariantMetadata + FromVariant> Iterator for Iter<'a, T> { } // TODO There's a macro for this, but it doesn't support generics yet; add support and use it -impl PartialEq for TypedArray { +impl PartialEq for Array { #[inline] fn eq(&self, other: &Self) -> bool { unsafe { @@ -768,7 +768,7 @@ impl PartialEq for TypedArray { } } -impl PartialOrd for TypedArray { +impl PartialOrd for Array { #[inline] fn partial_cmp(&self, other: &Self) -> Option { let op_less = |lhs, rhs| unsafe { @@ -793,14 +793,14 @@ impl PartialOrd for TypedArray { // ---------------------------------------------------------------------------------------------------------------------------------------------- -/// Constructs [`TypedArray`] literals, similar to Rust's standard `vec!` macro. +/// Constructs [`Array`] literals, similar to Rust's standard `vec!` macro. /// /// The type of the array is inferred from the arguments. /// /// Example: /// ```no_run /// # use godot::prelude::*; -/// let arr = array![3, 1, 4]; // TypedArray +/// let arr = array![3, 1, 4]; // Array /// ``` /// /// To create an `Array` of variants, see the [`varray!`] macro. @@ -808,7 +808,7 @@ impl PartialOrd for TypedArray { macro_rules! array { ($($elements:expr),* $(,)?) => { { - let mut array = $crate::builtin::TypedArray::default(); + let mut array = $crate::builtin::Array::default(); $( array.push($elements); )* @@ -817,14 +817,14 @@ macro_rules! array { }; } -/// Constructs [`Array`] literals, similar to Rust's standard `vec!` macro. +/// Constructs [`VariantArray`] literals, similar to Rust's standard `vec!` macro. /// /// The type of the array is always [`Variant`]. /// /// Example: /// ```no_run /// # use godot::prelude::*; -/// let arr: Array = varray![42_i64, "hello", true]; +/// let arr: VariantArray = varray![42_i64, "hello", true]; /// ``` /// /// To create a typed `Array` with a single element type, see the [`array!`] macro. @@ -834,7 +834,7 @@ macro_rules! varray { ($($elements:expr),* $(,)?) => { { use $crate::builtin::ToVariant as _; - let mut array = $crate::builtin::Array::default(); + let mut array = $crate::builtin::VariantArray::default(); $( array.push($elements.to_variant()); )* diff --git a/godot-core/src/builtin/dictionary.rs b/godot-core/src/builtin/dictionary.rs index 82e08c9f3..8805c4fa8 100644 --- a/godot-core/src/builtin/dictionary.rs +++ b/godot-core/src/builtin/dictionary.rs @@ -14,7 +14,7 @@ use std::ptr::addr_of_mut; use sys::types::OpaqueDictionary; use sys::{ffi_methods, interface_fn, GodotFfi}; -use super::Array; +use super::VariantArray; /// Godot's `Dictionary` type. /// @@ -23,7 +23,7 @@ use super::Array; /// /// # Thread safety /// -/// The same principles apply as for [`Array`]. Consult its documentation for details. +/// The same principles apply as for [`VariantArray`]. Consult its documentation for details. #[repr(C)] pub struct Dictionary { opaque: OpaqueDictionary, @@ -131,7 +131,7 @@ impl Dictionary { /// Returns `true` if the dictionary contains all the given keys. /// /// _Godot equivalent: `has_all`_ - pub fn contains_all_keys(&self, keys: Array) -> bool { + pub fn contains_all_keys(&self, keys: VariantArray) -> bool { self.as_inner().has_all(keys) } @@ -143,14 +143,14 @@ impl Dictionary { /// Creates a new `Array` containing all the keys currently in the dictionary. /// /// _Godot equivalent: `keys`_ - pub fn keys_array(&self) -> Array { + pub fn keys_array(&self) -> VariantArray { self.as_inner().keys() } /// Creates a new `Array` containing all the values currently in the dictionary. /// /// _Godot equivalent: `values`_ - pub fn values_array(&self) -> Array { + pub fn values_array(&self) -> VariantArray { self.as_inner().values() } @@ -464,7 +464,7 @@ impl<'a> Keys<'a> { } /// Returns an array of the keys - pub fn array(self) -> Array { + pub fn array(self) -> VariantArray { // Can only be called assert!(self.iter.is_first); self.iter.dictionary.keys_array() diff --git a/godot-core/src/builtin/mod.rs b/godot-core/src/builtin/mod.rs index c407881d7..1800f3a4b 100644 --- a/godot-core/src/builtin/mod.rs +++ b/godot-core/src/builtin/mod.rs @@ -35,7 +35,7 @@ // Re-export macros. pub use crate::{array, dict, varray}; -pub use array_inner::{Array, TypedArray}; +pub use array_inner::{Array, VariantArray}; pub use basis::*; pub use color::*; pub use dictionary_inner::Dictionary; diff --git a/godot-core/src/builtin/packed_array.rs b/godot-core/src/builtin/packed_array.rs index 52d39750a..f42573a78 100644 --- a/godot-core/src/builtin/packed_array.rs +++ b/godot-core/src/builtin/packed_array.rs @@ -376,7 +376,7 @@ macro_rules! impl_packed_array { } } - impl_builtin_froms!($PackedArray; Array => $from_array); + impl_builtin_froms!($PackedArray; VariantArray => $from_array); impl fmt::Debug for $PackedArray { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/itest/rust/src/array_test.rs b/itest/rust/src/array_test.rs index c54a689c8..9f830d327 100644 --- a/itest/rust/src/array_test.rs +++ b/itest/rust/src/array_test.rs @@ -9,12 +9,12 @@ use godot::prelude::*; #[itest] fn array_default() { - assert_eq!(Array::default().len(), 0); + assert_eq!(VariantArray::default().len(), 0); } #[itest] fn array_new() { - assert_eq!(Array::new().len(), 0); + assert_eq!(VariantArray::new().len(), 0); } #[itest] @@ -31,7 +31,7 @@ fn array_eq() { fn typed_array_from_to_variant() { let array = array![1, 2]; let variant = array.to_variant(); - let result = TypedArray::try_from_variant(&variant); + let result = Array::try_from_variant(&variant); assert_eq!(result, Ok(array)); } @@ -39,14 +39,14 @@ fn typed_array_from_to_variant() { fn untyped_array_from_to_variant() { let array = varray![1, 2]; let variant = array.to_variant(); - let result = Array::try_from_variant(&variant); + let result = VariantArray::try_from_variant(&variant); assert_eq!(result, Ok(array)); } #[itest] fn array_from_packed_array() { let packed_array = PackedInt32Array::from(&[42]); - let mut array = Array::from(&packed_array); + let mut array = VariantArray::from(&packed_array); // This tests that the resulting array doesn't secretly have a runtime type assigned to it, // which is not reflected in our static type. It would make sense if it did, but Godot decided // otherwise: we get an untyped array. @@ -56,7 +56,7 @@ fn array_from_packed_array() { #[itest] fn array_from_iterator() { - let array = TypedArray::from_iter([1, 2]); + let array = Array::from_iter([1, 2]); assert_eq!(array.len(), 2); assert_eq!(array.get(0), 1); @@ -65,7 +65,7 @@ fn array_from_iterator() { #[itest] fn array_from_slice() { - let array = TypedArray::from(&[1, 2]); + let array = Array::from(&[1, 2]); assert_eq!(array.len(), 2); assert_eq!(array.get(0), 1); @@ -108,7 +108,7 @@ fn array_duplicate_shallow() { let subarray = array![2, 3]; let array = varray![1, subarray]; let duplicate = array.duplicate_shallow(); - TypedArray::::try_from_variant(&duplicate.get(1)) + Array::::try_from_variant(&duplicate.get(1)) .unwrap() .set(0, 4); assert_eq!(subarray.get(0), 4); @@ -119,7 +119,7 @@ fn array_duplicate_deep() { let subarray = array![2, 3]; let array = varray![1, subarray]; let duplicate = array.duplicate_deep(); - TypedArray::::try_from_variant(&duplicate.get(1)) + Array::::try_from_variant(&duplicate.get(1)) .unwrap() .set(0, 4); assert_eq!(subarray.get(0), 2); @@ -134,7 +134,7 @@ fn array_slice_shallow() { let subarray = array![2, 3]; let array = varray![1, subarray]; let slice = array.slice_shallow(1, 2, None); - TypedArray::::try_from_variant(&slice.get(0)) + Array::::try_from_variant(&slice.get(0)) .unwrap() .set(0, 4); assert_eq!(subarray.get(0), 4); @@ -149,7 +149,7 @@ fn array_slice_deep() { let subarray = array![2, 3]; let array = varray![1, subarray]; let slice = array.slice_deep(1, 2, None); - TypedArray::::try_from_variant(&slice.get(0)) + Array::::try_from_variant(&slice.get(0)) .unwrap() .set(0, 4); assert_eq!(subarray.get(0), 2); @@ -173,7 +173,7 @@ fn array_first_last() { assert_eq!(array.first(), Some(1)); assert_eq!(array.last(), Some(2)); - let empty_array = Array::new(); + let empty_array = VariantArray::new(); assert_eq!(empty_array.first(), None); assert_eq!(empty_array.last(), None); @@ -220,7 +220,7 @@ fn array_min_max() { assert_eq!(uncomparable_array.min(), None); assert_eq!(uncomparable_array.max(), None); - let empty_array = Array::new(); + let empty_array = VariantArray::new(); assert_eq!(empty_array.min(), None); assert_eq!(empty_array.max(), None); @@ -228,7 +228,7 @@ fn array_min_max() { #[itest] fn array_pick_random() { - assert_eq!(Array::new().pick_random(), None); + assert_eq!(VariantArray::new().pick_random(), None); assert_eq!(array![1].pick_random(), Some(1)); } @@ -330,10 +330,7 @@ fn array_mixed_values() { PackedByteArray::try_from_variant(&array.get(2)).unwrap(), packed_array ); - assert_eq!( - TypedArray::try_from_variant(&array.get(3)).unwrap(), - typed_array - ); + assert_eq!(Array::try_from_variant(&array.get(3)).unwrap(), typed_array); assert_eq!( Gd::::try_from_variant(&array.get(4)) .unwrap() @@ -384,7 +381,7 @@ fn untyped_array_return_from_godot_func() { assert_eq!(result, varray![child, Variant::nil(), NodePath::default()]); } -// TODO All API functions that take a `TypedArray` are even more obscure and not included in +// TODO All API functions that take a `Array` are even more obscure and not included in // `SELECTED_CLASSES`. Decide if this test is worth having `Texture2DArray` and `Image` and their // ancestors in the list. #[itest] @@ -431,22 +428,22 @@ struct ArrayTest; #[godot_api] impl ArrayTest { #[func] - fn pass_untyped_array(&self, array: Array) -> i64 { + fn pass_untyped_array(&self, array: VariantArray) -> i64 { array.len().try_into().unwrap() } #[func] - fn return_untyped_array(&self) -> Array { + fn return_untyped_array(&self) -> VariantArray { varray![42, "answer"] } #[func] - fn pass_typed_array(&self, array: TypedArray) -> i64 { + fn pass_typed_array(&self, array: Array) -> i64 { array.iter_shared().sum() } #[func] - fn return_typed_array(&self, n: i64) -> TypedArray { + fn return_typed_array(&self, n: i64) -> Array { (1..(n + 1)).collect() } } diff --git a/itest/rust/src/builtin_test.rs b/itest/rust/src/builtin_test.rs index 87f1ba692..f6e58d95c 100644 --- a/itest/rust/src/builtin_test.rs +++ b/itest/rust/src/builtin_test.rs @@ -25,7 +25,7 @@ fn test_builtins_vector2() { #[itest] fn test_builtins_array() { - let array = Array::default(); + let array = VariantArray::default(); let mut inner: InnerArray = array.as_inner(); let a = 7.to_variant(); diff --git a/itest/rust/src/runner.rs b/itest/rust/src/runner.rs index e617ecb05..437b5468b 100644 --- a/itest/rust/src/runner.rs +++ b/itest/rust/src/runner.rs @@ -5,7 +5,7 @@ */ use godot::bind::{godot_api, GodotClass}; -use godot::builtin::{Array, ToVariant, Variant}; +use godot::builtin::{ToVariant, Variant, VariantArray}; use crate::RustTestCase; use std::time::{Duration, Instant}; @@ -25,7 +25,7 @@ impl IntegrationTests { #[func] fn run_all_tests( &mut self, - gdscript_tests: Array, + gdscript_tests: VariantArray, gdscript_file_count: i64, allow_focus: bool, ) -> bool { @@ -72,7 +72,7 @@ impl IntegrationTests { } } - fn run_gdscript_tests(&mut self, tests: Array) { + fn run_gdscript_tests(&mut self, tests: VariantArray) { let mut last_file = None; for test in tests.iter_shared() { let result = test.call("run", &[]); diff --git a/itest/rust/src/variant_test.rs b/itest/rust/src/variant_test.rs index ae5c3e8db..ff827eb39 100644 --- a/itest/rust/src/variant_test.rs +++ b/itest/rust/src/variant_test.rs @@ -10,7 +10,7 @@ use godot::builtin::{ }; use godot::engine::Node2D; use godot::obj::InstanceId; -use godot::prelude::{Array, Basis, Dictionary, VariantConversionError}; +use godot::prelude::{Basis, Dictionary, VariantArray, VariantConversionError}; use godot::sys::{GodotFfi, VariantOperator, VariantType}; use std::cmp::Ordering; use std::fmt::{Debug, Display}; @@ -303,7 +303,7 @@ fn variant_conversion_fails() { Err(VariantConversionError) ); assert_eq!( - Array::default().to_variant().try_to::(), + VariantArray::default().to_variant().try_to::(), Err(VariantConversionError) ); //assert_eq!( @@ -327,7 +327,10 @@ fn variant_type_correct() { StringName::from("string_name").to_variant().get_type(), VariantType::StringName ); - assert_eq!(Array::default().to_variant().get_type(), VariantType::Array); + assert_eq!( + VariantArray::default().to_variant().get_type(), + VariantType::Array + ); assert_eq!( Dictionary::default().to_variant().get_type(), VariantType::Dictionary