Function ref_to_arg
pub fn ref_to_arg<'r, T>(ref_val: &'r T) -> impl AsArg<T> + 'rwhere
T: ToGodot + 'r,
Expand description
Generic abstraction over &T
references that should be passed as AsArg<T>
.
Useful for generic programming: you have references, and want the argument conversion to benefit from borrowing whenever possible.
If you no longer need the value at the call site, consider using owned_into_arg(value)
instead.
ยงExample
use godot::prelude::*;
use godot::meta::{ArrayElement, ref_to_arg};
// Could use `impl AsArg<T>` and forward it, but let's demonstrate `&T` here.
fn log_and_push<T>(arr: &mut Array<T>, value: &T)
where
T: ArrayElement + ToGodot + std::fmt::Debug,
{
println!("Add value: {value:?}");
arr.push(ref_to_arg(value));
}