Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Nov 3, 2024
1 parent 5741eed commit 7149146
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
4 changes: 2 additions & 2 deletions godot-core/src/builtin/collections/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/obj/gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ impl<T: GodotClass> ArrayElement for Option<Gd<T>> {
}
}

impl<'r, T: GodotClass + ArgTarget> AsArg<Gd<T>> for &'r Gd<T> {
impl<'r, T: GodotClass> AsArg<Gd<T>> for &'r Gd<T> {
fn into_arg<'cow>(self) -> CowArg<'cow, Gd<T>>
where
'r: 'cow, // Original reference must be valid for at least as long as the returned cow.
Expand Down
29 changes: 6 additions & 23 deletions itest/rust/src/builtin_tests/containers/array_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")]
Expand All @@ -514,36 +514,19 @@ 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!");

a.resize(10, &new);
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());
Expand Down
10 changes: 5 additions & 5 deletions itest/rust/src/builtin_tests/convert_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn vec_to_array() {

let from = vec![GString::from("Hello"), GString::from("World")];
let to = from.to_variant().to::<Array<GString>>();
assert_eq!(to, array![GString::from("Hello"), GString::from("World")]);
assert_eq!(to, array!["Hello", "World"]);

// Invalid conversion.
let from = vec![1, 2, 3];
Expand All @@ -268,7 +268,7 @@ fn array_to_vec() {
let to = from.to_variant().to::<Vec<i32>>();
assert_eq!(to, vec![1, 2, 3]);

let from = array![GString::from("Hello"), GString::from("World")];
let from: Array<GString> = array!["Hello", "World"];
let to = from.to_variant().to::<Vec<GString>>();
assert_eq!(to, vec![GString::from("Hello"), GString::from("World")]);

Expand All @@ -286,7 +286,7 @@ fn rust_array_to_array() {

let from = [GString::from("Hello"), GString::from("World")];
let to = from.to_variant().to::<Array<GString>>();
assert_eq!(to, array![GString::from("Hello"), GString::from("World")]);
assert_eq!(to, array!["Hello", "World"]);

// Invalid conversion.
let from = [1, 2, 3];
Expand All @@ -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<GString> = array!["Hello", "World"];
let to = from.to_variant().to::<[GString; 2]>();
assert_eq!(to, [GString::from("Hello"), GString::from("World")]);

Expand All @@ -318,7 +318,7 @@ fn slice_to_array() {

let from = &[GString::from("Hello"), GString::from("World")];
let to = from.to_variant().to::<Array<GString>>();
assert_eq!(to, array![GString::from("Hello"), GString::from("World")]);
assert_eq!(to, array!["Hello", "World"]);

// Invalid conversion.
let from = &[1, 2, 3];
Expand Down
2 changes: 1 addition & 1 deletion itest/rust/src/object_tests/object_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ pub mod object_test_gd {

#[func]
fn return_nested_self() -> Array<Gd<<Self as GodotClass>::Base>> {
array![Self::return_self().upcast()]
array![&Self::return_self().upcast()]
}
}

Expand Down

0 comments on commit 7149146

Please sign in to comment.