Skip to content

Commit

Permalink
Rename ApiParam::value_to_arg() -> owned_to_arg(), hide Arg type
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Nov 5, 2024
1 parent 361aec8 commit 99369f7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 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 @@ -947,7 +947,7 @@ impl<'r, T: ArrayElement> AsArg<Array<T>> for &'r Array<T> {
impl<T: ArrayElement> ApiParam for Array<T> {
type Arg<'v> = CowArg<'v, Self>;

fn value_to_arg<'v>(self) -> Self::Arg<'v> {
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
CowArg::Owned(self)
}

Expand Down Expand Up @@ -1221,7 +1221,7 @@ impl<T: ArrayElement + ToGodot> Extend<T> for Array<T> {
// A faster implementation using `resize()` and direct pointer writes might still be possible.
// Note that this could technically also use iter(), since no moves need to happen (however Extend requires IntoIterator).
for item in iter.into_iter() {
self.push(ApiParam::value_to_arg(item));
self.push(ApiParam::owned_to_arg(item));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/collections/packed_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ macro_rules! impl_packed_array {
// A faster implementation using `resize()` and direct pointer writes might still be
// possible.
for item in iter.into_iter() {
self.push(meta::ApiParam::value_to_arg(item));
self.push(meta::ApiParam::owned_to_arg(item));
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions godot-core/src/meta/as_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::ffi::CStr;
/// Implicitly converting from `T` for by-ref builtins is explicitly not supported. This emphasizes that there is no need to consume the object,
/// thus discourages unnecessary cloning.
///
/// If you need to pass owned values in generic code, you can use [`ApiParam::value_to_arg()`].
/// If you need to pass owned values in generic code, you can use [`ApiParam::owned_to_arg()`].
///
/// # Performance for strings
/// Godot has three string types: [`GString`], [`StringName`] and [`NodePath`]. Conversions between those three, as well as between `String` and
Expand Down Expand Up @@ -106,7 +106,7 @@ macro_rules! impl_asarg_by_value {
impl $crate::meta::ApiParam for $T {
type Arg<'v> = $T;

fn value_to_arg<'v>(self) -> Self::Arg<'v> {
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
self
}

Expand Down Expand Up @@ -139,7 +139,7 @@ macro_rules! impl_asarg_by_ref {
impl $crate::meta::ApiParam for $T {
type Arg<'v> = $crate::meta::CowArg<'v, $T>;

fn value_to_arg<'v>(self) -> Self::Arg<'v> {
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
$crate::meta::CowArg::Owned(self)
}

Expand Down Expand Up @@ -252,22 +252,23 @@ impl AsArg<NodePath> for &String {
/// Implemented for all parameter types `T` that are allowed to receive [impl `AsArg<T>`][AsArg].
pub trait ApiParam: GodotType
// GodotType bound not required right now, but conceptually should always be the case.
where
Self: Sized,
{
/// Canonical argument passing type, either `T` or an internally-used CoW type.
///
/// The general rule is that `Copy` types are passed by value, while the rest is passed by reference.
///
/// This associated type is closely related to [`ToGodot::ToVia<'v>`][crate::meta::ToGodot::ToVia] and may be reorganized.
/// This associated type is closely related to [`ToGodot::ToVia<'v>`][crate::meta::ToGodot::ToVia] and may be reorganized in the future.
#[doc(hidden)]
type Arg<'v>: AsArg<Self>
where
Self: 'v;

/// Converts an owned value to the canonical argument type, which can be passed to [`impl AsArg<T>`][AsArg].
///
/// Useful in generic contexts where only a value is available, and one doesn't want to dispatch between value/reference.
fn value_to_arg<'v>(self) -> Self::Arg<'v>;
///
/// You should not rely on the exact return type, as it may change in future versions; treat it like `impl AsArg<Self>`.
fn owned_to_arg<'v>(self) -> Self::Arg<'v>;

/// Converts an argument to a shared reference.
///
Expand Down
4 changes: 2 additions & 2 deletions godot-core/src/obj/gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ impl<'r, T: GodotClass> AsArg<Gd<T>> for &'r Gd<T> {
impl<T: GodotClass> ApiParam for Gd<T> {
type Arg<'v> = CowArg<'v, Gd<T>>;

fn value_to_arg<'v>(self) -> Self::Arg<'v> {
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
CowArg::Owned(self)
}

Expand All @@ -806,7 +806,7 @@ impl<'r, T: GodotClass> AsArg<Option<Gd<T>>> for Option<&'r Gd<T>> {
impl<T: GodotClass> ApiParam for Option<Gd<T>> {
type Arg<'v> = CowArg<'v, Option<Gd<T>>>;

fn value_to_arg<'v>(self) -> Self::Arg<'v> {
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
CowArg::Owned(self)
}

Expand Down

0 comments on commit 99369f7

Please sign in to comment.