From 71491466cc11e4c9c3933c361b55eb157b2073d2 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Sun, 3 Nov 2024 22:30:33 +0100 Subject: [PATCH] ++ --- godot-core/src/builtin/collections/array.rs | 4 +-- godot-core/src/obj/gd.rs | 2 +- .../builtin_tests/containers/array_test.rs | 29 ++++--------------- itest/rust/src/builtin_tests/convert_test.rs | 10 +++---- itest/rust/src/object_tests/object_test.rs | 2 +- 5 files changed, 15 insertions(+), 32 deletions(-) diff --git a/godot-core/src/builtin/collections/array.rs b/godot-core/src/builtin/collections/array.rs index 4765404af..73d293b53 100644 --- a/godot-core/src/builtin/collections/array.rs +++ b/godot-core/src/builtin/collections/array.rs @@ -86,8 +86,8 @@ use sys::{ffi_methods, interface_fn, GodotFfi}; /// # use godot::prelude::*; /// // VariantArray allows dynamic element types. /// let mut array = VariantArray::new(); -/// array.push(10.to_variant()); -/// array.push("Hello".to_variant()); +/// array.push(&10.to_variant()); +/// array.push(&"Hello".to_variant()); /// /// // Or equivalent, use the `varray!` macro which converts each element. /// let array = varray![10, "Hello"]; diff --git a/godot-core/src/obj/gd.rs b/godot-core/src/obj/gd.rs index 4dbf873e7..35d59a69a 100644 --- a/godot-core/src/obj/gd.rs +++ b/godot-core/src/obj/gd.rs @@ -772,7 +772,7 @@ impl ArrayElement for Option> { } } -impl<'r, T: GodotClass + ArgTarget> AsArg> for &'r Gd { +impl<'r, T: GodotClass> AsArg> for &'r Gd { fn into_arg<'cow>(self) -> CowArg<'cow, Gd> where 'r: 'cow, // Original reference must be valid for at least as long as the returned cow. diff --git a/itest/rust/src/builtin_tests/containers/array_test.rs b/itest/rust/src/builtin_tests/containers/array_test.rs index cc03189a1..8ee1d5157 100644 --- a/itest/rust/src/builtin_tests/containers/array_test.rs +++ b/itest/rust/src/builtin_tests/containers/array_test.rs @@ -436,7 +436,7 @@ fn typed_array_return_from_godot_func() { node.queue_free(); // Do not leak even if the test fails. let children = node.get_children(); - assert_eq!(children, array![child]); + assert_eq!(children, array![&child]); } #[itest] @@ -488,8 +488,8 @@ fn array_sort_custom() { fn array_binary_search_custom() { let a = array![5, 4, 2, 1]; let func = backwards_sort_callable(); - assert_eq!(a.bsearch_custom(&1, func.clone()), 3); - assert_eq!(a.bsearch_custom(&3, func), 2); + assert_eq!(a.bsearch_custom(1, func.clone()), 3); + assert_eq!(a.bsearch_custom(3, func), 2); } #[cfg(since_api = "4.2")] @@ -514,13 +514,7 @@ fn array_shrink() { #[itest] fn array_resize() { - let mut a = array![ - GString::from("hello"), - GString::from("bar"), - GString::from("mixed"), - GString::from("baz"), - GString::from("meow") - ]; + let mut a = array!["hello", "bar", "mixed", "baz", "meow"]; let new = GString::from("new!"); @@ -528,22 +522,11 @@ fn array_resize() { assert_eq!(a.len(), 10); assert_eq!( a, - array![ - GString::from("hello"), - GString::from("bar"), - GString::from("mixed"), - GString::from("baz"), - GString::from("meow"), - new.clone(), - new.clone(), - new.clone(), - new.clone(), - new.clone(), - ] + array!["hello", "bar", "mixed", "baz", "meow", &new, &new, &new, &new, &new] ); a.resize(2, &new); - assert_eq!(a, array![GString::from("hello"), GString::from("bar")]); + assert_eq!(a, array!["hello", "bar"]); a.resize(0, &new); assert_eq!(a, Array::new()); diff --git a/itest/rust/src/builtin_tests/convert_test.rs b/itest/rust/src/builtin_tests/convert_test.rs index 995313e38..c28733b23 100644 --- a/itest/rust/src/builtin_tests/convert_test.rs +++ b/itest/rust/src/builtin_tests/convert_test.rs @@ -254,7 +254,7 @@ fn vec_to_array() { let from = vec![GString::from("Hello"), GString::from("World")]; let to = from.to_variant().to::>(); - assert_eq!(to, array![GString::from("Hello"), GString::from("World")]); + assert_eq!(to, array!["Hello", "World"]); // Invalid conversion. let from = vec![1, 2, 3]; @@ -268,7 +268,7 @@ fn array_to_vec() { let to = from.to_variant().to::>(); assert_eq!(to, vec![1, 2, 3]); - let from = array![GString::from("Hello"), GString::from("World")]; + let from: Array = array!["Hello", "World"]; let to = from.to_variant().to::>(); assert_eq!(to, vec![GString::from("Hello"), GString::from("World")]); @@ -286,7 +286,7 @@ fn rust_array_to_array() { let from = [GString::from("Hello"), GString::from("World")]; let to = from.to_variant().to::>(); - assert_eq!(to, array![GString::from("Hello"), GString::from("World")]); + assert_eq!(to, array!["Hello", "World"]); // Invalid conversion. let from = [1, 2, 3]; @@ -300,7 +300,7 @@ fn array_to_rust_array() { let to = from.to_variant().to::<[i32; 3]>(); assert_eq!(to, [1, 2, 3]); - let from = array![GString::from("Hello"), GString::from("World")]; + let from: Array = array!["Hello", "World"]; let to = from.to_variant().to::<[GString; 2]>(); assert_eq!(to, [GString::from("Hello"), GString::from("World")]); @@ -318,7 +318,7 @@ fn slice_to_array() { let from = &[GString::from("Hello"), GString::from("World")]; let to = from.to_variant().to::>(); - assert_eq!(to, array![GString::from("Hello"), GString::from("World")]); + assert_eq!(to, array!["Hello", "World"]); // Invalid conversion. let from = &[1, 2, 3]; diff --git a/itest/rust/src/object_tests/object_test.rs b/itest/rust/src/object_tests/object_test.rs index 1c4500295..a116573a8 100644 --- a/itest/rust/src/object_tests/object_test.rs +++ b/itest/rust/src/object_tests/object_test.rs @@ -996,7 +996,7 @@ pub mod object_test_gd { #[func] fn return_nested_self() -> Array::Base>> { - array![Self::return_self().upcast()] + array![&Self::return_self().upcast()] } }