Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions godot-codegen/src/generator/functions_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,10 @@ pub(crate) fn make_param_or_field_type(
special_ty = Some(quote! { CowArg<#lft, #ty> });

match decl {
FnParamDecl::FnPublic => quote! { impl AsArg<#ty> },
FnParamDecl::FnPublicLifetime => quote! { impl AsArg<#ty> + 'ex },
FnParamDecl::FnPublic => quote! { impl AsArg<#ty> + ShouldBePassedAsRef },
FnParamDecl::FnPublicLifetime => {
quote! { impl AsArg<#ty> + ShouldBePassedAsRef + 'ex }
}
FnParamDecl::FnInternal => quote! { CowArg<#ty> },
FnParamDecl::Field => quote! { CowArg<'ex, #ty> },
}
Expand Down
2 changes: 1 addition & 1 deletion godot-codegen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn make_imports() -> TokenStream {
quote! {
use godot_ffi as sys;
use crate::builtin::*;
use crate::meta::{AsArg, ClassId, CowArg, InParamTuple, OutParamTuple, ParamTuple, RawPtr, RefArg, Signature};
use crate::meta::{AsArg, ClassId, CowArg, InParamTuple, OutParamTuple, ParamTuple, RawPtr, RefArg, ShouldBePassedAsRef, Signature};
use crate::classes::native::*;
use crate::classes::Object;
use crate::obj::Gd;
Expand Down
14 changes: 7 additions & 7 deletions godot-core/src/builtin/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use godot_ffi as sys;
use sys::{ffi_methods, ExtVariantType, GodotFfi};

use crate::builtin::{inner, AnyArray, CowStr, StringName, Variant};
use crate::meta::{GodotType, ToGodot};
use crate::meta::{GodotType, ShouldBePassedAsRef, ToGodot};
use crate::obj::bounds::DynMemory;
use crate::obj::{Bounds, Gd, GodotClass, InstanceId, Singleton};
use crate::{classes, meta};
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Callable {
pub fn from_object_method<T, S>(object: &Gd<T>, method_name: S) -> Self
where
T: GodotClass, // + Inherits<Object>,
S: meta::AsArg<StringName>,
S: meta::AsArg<StringName> + ShouldBePassedAsRef,
{
meta::arg_into_ref!(method_name);

Expand Down Expand Up @@ -79,7 +79,7 @@ impl Callable {
#[cfg(since_api = "4.3")]
pub fn from_variant_method<S>(variant: &Variant, method_name: S) -> Self
where
S: meta::AsArg<StringName>,
S: meta::AsArg<StringName> + ShouldBePassedAsRef,
{
meta::arg_into_ref!(method_name);
inner::InnerCallable::create(variant, method_name)
Expand All @@ -94,8 +94,8 @@ impl Callable {
/// reflection APIs at the moment.
#[cfg(since_api = "4.4")]
pub fn from_class_static(
class_name: impl meta::AsArg<StringName>,
function_name: impl meta::AsArg<StringName>,
class_name: impl meta::AsArg<StringName> + ShouldBePassedAsRef,
function_name: impl meta::AsArg<StringName> + ShouldBePassedAsRef,
) -> Self {
meta::arg_into_owned!(class_name);
meta::arg_into_owned!(function_name);
Expand Down Expand Up @@ -125,8 +125,8 @@ impl Callable {
#[deprecated = "Renamed to `from_class_static`."]
#[cfg(since_api = "4.4")]
pub fn from_local_static(
class_name: impl meta::AsArg<StringName>,
function_name: impl meta::AsArg<StringName>,
class_name: impl meta::AsArg<StringName> + ShouldBePassedAsRef,
function_name: impl meta::AsArg<StringName> + ShouldBePassedAsRef,
) -> Self {
Self::from_class_static(class_name, function_name)
}
Expand Down
4 changes: 2 additions & 2 deletions godot-core/src/builtin/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::classes::object::ConnectFlags;
use crate::classes::Object;
use crate::global::Error;
use crate::meta;
use crate::meta::{FromGodot, GodotType, ToGodot};
use crate::meta::{FromGodot, GodotType, ShouldBePassedAsRef, ToGodot};
use crate::obj::bounds::DynMemory;
use crate::obj::{Bounds, EngineBitfield, Gd, GodotClass, InstanceId};

Expand All @@ -42,7 +42,7 @@ impl Signal {
pub fn from_object_signal<T, S>(object: &Gd<T>, signal_name: S) -> Self
where
T: GodotClass,
S: meta::AsArg<StringName>,
S: meta::AsArg<StringName> + ShouldBePassedAsRef,
{
meta::arg_into_ref!(signal_name);

Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/strings/gstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use sys::{ffi_methods, interface_fn, ExtVariantType, GodotFfi};
use crate::builtin::strings::{pad_if_needed, Encoding};
use crate::builtin::{inner, NodePath, StringName, Variant};
use crate::meta::error::StringError;
use crate::meta::AsArg;
use crate::meta::{AsArg, ShouldBePassedAsRef};
use crate::{impl_shared_string_api, meta};

/// Godot's reference counted string type.
Expand Down
30 changes: 15 additions & 15 deletions godot-core/src/builtin/strings/string_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ macro_rules! impl_shared_string_api {
/// Find first occurrence of `what` and return index, or `None` if not found.
///
/// Check [`find_ex()`](Self::find_ex) for all custom options.
pub fn find(&self, what: impl AsArg<GString>) -> Option<usize> {
pub fn find(&self, what: impl AsArg<GString> + ShouldBePassedAsRef) -> Option<usize> {
self.find_ex(what).done()
}

Expand Down Expand Up @@ -73,7 +73,7 @@ macro_rules! impl_shared_string_api {
#[doc(alias = "findn", alias = "rfind", alias = "rfindn")]
pub fn find_ex<'s, 'w>(
&'s self,
what: impl AsArg<GString> + 'w,
what: impl AsArg<GString> + ShouldBePassedAsRef + 'w,
) -> ExFind<'s, 'w> {
ExFind::new(self, what.into_arg())
}
Expand All @@ -93,7 +93,7 @@ macro_rules! impl_shared_string_api {
/// Splits the string according to `delimiter`.
///
/// See [`split_ex()`][Self::split_ex] if you need further configuration.
pub fn split(&self, delimiter: impl AsArg<GString>) -> $crate::builtin::PackedStringArray {
pub fn split(&self, delimiter: impl AsArg<GString> + ShouldBePassedAsRef) -> $crate::builtin::PackedStringArray {
self.split_ex(delimiter).done()
}

Expand Down Expand Up @@ -132,7 +132,7 @@ macro_rules! impl_shared_string_api {
/// This is faster than [`split()`][Self::split], if you only need one substring.
pub fn get_slice(
&self,
delimiter: impl AsArg<GString>,
delimiter: impl AsArg<GString> + ShouldBePassedAsRef,
slice: usize,
) -> Option<GString> {
let sliced = self.as_inner().get_slice(delimiter, slice as i64);
Expand All @@ -156,7 +156,7 @@ macro_rules! impl_shared_string_api {
/// Returns the total number of slices, when the string is split with the given delimiter.
///
/// See also [`split()`][Self::split] and [`get_slice()`][Self::get_slice].
pub fn get_slice_count(&self, delimiter: impl AsArg<GString>) -> usize {
pub fn get_slice_count(&self, delimiter: impl AsArg<GString> + ShouldBePassedAsRef) -> usize {
self.as_inner().get_slice_count(delimiter) as usize
}

Expand All @@ -171,7 +171,7 @@ macro_rules! impl_shared_string_api {
/// If the position is out of bounds, the string will be inserted at the end.
///
/// Consider using [`format()`](Self::format) for more flexibility.
pub fn insert(&self, position: usize, what: impl AsArg<GString>) -> GString {
pub fn insert(&self, position: usize, what: impl AsArg<GString> + ShouldBePassedAsRef) -> GString {
self.as_inner().insert(position as i64, what)
}

Expand All @@ -188,7 +188,7 @@ macro_rules! impl_shared_string_api {
pub fn format_with_placeholder(
&self,
array_or_dict: &Variant,
placeholder: impl AsArg<GString>,
placeholder: impl AsArg<GString> + ShouldBePassedAsRef,
) -> GString {
self.as_inner().format(array_or_dict, placeholder)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ macro_rules! impl_shared_string_api {
/// roughly matches the alphabetical order.
///
/// See also [`nocasecmp_to()`](Self::nocasecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
pub fn casecmp_to(&self, to: impl AsArg<GString>) -> std::cmp::Ordering {
pub fn casecmp_to(&self, to: impl AsArg<GString> + ShouldBePassedAsRef) -> std::cmp::Ordering {
sys::i64_to_ordering(self.as_inner().casecmp_to(to))
}

Expand All @@ -243,7 +243,7 @@ macro_rules! impl_shared_string_api {
/// roughly matches the alphabetical order.
///
/// See also [`casecmp_to()`](Self::casecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
pub fn nocasecmp_to(&self, to: impl AsArg<GString>) -> std::cmp::Ordering {
pub fn nocasecmp_to(&self, to: impl AsArg<GString> + ShouldBePassedAsRef) -> std::cmp::Ordering {
sys::i64_to_ordering(self.as_inner().nocasecmp_to(to))
}

Expand All @@ -260,7 +260,7 @@ macro_rules! impl_shared_string_api {
/// if shorter.
///
/// See also [`casecmp_to()`](Self::casecmp_to), [`naturalnocasecmp_to()`](Self::naturalnocasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
pub fn naturalcasecmp_to(&self, to: impl AsArg<GString>) -> std::cmp::Ordering {
pub fn naturalcasecmp_to(&self, to: impl AsArg<GString> + ShouldBePassedAsRef) -> std::cmp::Ordering {
sys::i64_to_ordering(self.as_inner().naturalcasecmp_to(to))
}

Expand All @@ -277,7 +277,7 @@ macro_rules! impl_shared_string_api {
/// if shorter.
///
/// See also [`casecmp_to()`](Self::casecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
pub fn naturalnocasecmp_to(&self, to: impl AsArg<GString>) -> std::cmp::Ordering {
pub fn naturalnocasecmp_to(&self, to: impl AsArg<GString> + ShouldBePassedAsRef) -> std::cmp::Ordering {
sys::i64_to_ordering(self.as_inner().naturalnocasecmp_to(to))
}

Expand All @@ -288,7 +288,7 @@ macro_rules! impl_shared_string_api {
///
/// See also [`casecmp_to()`](Self::casecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filenocasecmp_to()`](Self::filenocasecmp_to).
#[cfg(since_api = "4.3")]
pub fn filecasecmp_to(&self, to: impl AsArg<GString>) -> std::cmp::Ordering {
pub fn filecasecmp_to(&self, to: impl AsArg<GString> + ShouldBePassedAsRef) -> std::cmp::Ordering {
sys::i64_to_ordering(self.as_inner().filecasecmp_to(to))
}

Expand All @@ -299,7 +299,7 @@ macro_rules! impl_shared_string_api {
///
/// See also [`casecmp_to()`](Self::casecmp_to), [`naturalcasecmp_to()`](Self::naturalcasecmp_to), [`filecasecmp_to()`](Self::filecasecmp_to).
#[cfg(since_api = "4.3")]
pub fn filenocasecmp_to(&self, to: impl AsArg<GString>) -> std::cmp::Ordering {
pub fn filenocasecmp_to(&self, to: impl AsArg<GString> + ShouldBePassedAsRef) -> std::cmp::Ordering {
sys::i64_to_ordering(self.as_inner().filenocasecmp_to(to))
}

Expand All @@ -310,7 +310,7 @@ macro_rules! impl_shared_string_api {
///
/// Renamed from `match` because of collision with Rust keyword + possible confusion with `String::matches()` that can match regex.
#[doc(alias = "match")]
pub fn match_glob(&self, pattern: impl AsArg<GString>) -> bool {
pub fn match_glob(&self, pattern: impl AsArg<GString> + ShouldBePassedAsRef) -> bool {
self.as_inner().match_(pattern)
}

Expand All @@ -321,7 +321,7 @@ macro_rules! impl_shared_string_api {
///
/// Renamed from `matchn` because of collision with Rust keyword + possible confusion with `String::matches()` that can match regex.
#[doc(alias = "matchn")]
pub fn matchn_glob(&self, pattern: impl AsArg<GString>) -> bool {
pub fn matchn_glob(&self, pattern: impl AsArg<GString> + ShouldBePassedAsRef) -> bool {
self.as_inner().matchn(pattern)
}
}
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/strings/string_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use sys::{ffi_methods, ExtVariantType, GodotFfi};

use crate::builtin::{inner, Encoding, GString, NodePath, Variant};
use crate::meta::error::StringError;
use crate::meta::AsArg;
use crate::meta::{AsArg, ShouldBePassedAsRef};
use crate::{impl_shared_string_api, meta};

/// A string optimized for unique names.
Expand Down
8 changes: 6 additions & 2 deletions godot-core/src/builtin/variant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::classes;
use crate::meta::error::{ConvertError, FromVariantError};
use crate::meta::{
arg_into_ref, ffi_variant_type, ArrayElement, AsArg, EngineFromGodot, ExtVariantType,
FromGodot, GodotType, ToGodot,
FromGodot, GodotType, ShouldBePassedAsRef, ToGodot,
};

mod impls;
Expand Down Expand Up @@ -232,7 +232,11 @@ impl Variant {
/// * If the method does not exist or the signature is not compatible with the passed arguments.
/// * If the call causes an error.
#[inline]
pub fn call(&self, method: impl AsArg<StringName>, args: &[Variant]) -> Variant {
pub fn call(
&self,
method: impl AsArg<StringName> + ShouldBePassedAsRef,
args: &[Variant],
) -> Variant {
arg_into_ref!(method);
self.call_inner(method, args)
}
Expand Down
26 changes: 17 additions & 9 deletions godot-core/src/classes/type_safe_replacements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::classes::object::ConnectFlags;
use crate::classes::scene_tree::GroupCallFlags;
use crate::classes::{Object, SceneTree, Script};
use crate::global::Error;
use crate::meta::{arg_into_ref, AsArg, ToGodot};
use crate::meta::{arg_into_ref, AsArg, ShouldBePassedAsRef, ToGodot};
use crate::obj::{EngineBitfield, Gd};

impl Object {
Expand All @@ -36,13 +36,17 @@ impl Object {
self.raw_set_script(&script.to_variant());
}

pub fn connect(&mut self, signal: impl AsArg<StringName>, callable: &Callable) -> Error {
pub fn connect(
&mut self,
signal: impl AsArg<StringName> + ShouldBePassedAsRef,
callable: &Callable,
) -> Error {
self.raw_connect(signal, callable)
}

pub fn connect_flags(
&mut self,
signal: impl AsArg<StringName>,
signal: impl AsArg<StringName> + ShouldBePassedAsRef,
callable: &Callable,
flags: ConnectFlags,
) -> Error {
Expand All @@ -59,8 +63,8 @@ impl SceneTree {
pub fn call_group_flags(
&mut self,
flags: GroupCallFlags,
group: impl AsArg<StringName>,
method: impl AsArg<StringName>,
group: impl AsArg<StringName> + ShouldBePassedAsRef,
method: impl AsArg<StringName> + ShouldBePassedAsRef,
varargs: &[Variant],
) {
self.raw_call_group_flags(flags.ord() as i64, group, method, varargs)
Expand All @@ -69,23 +73,27 @@ impl SceneTree {
pub fn set_group_flags(
&mut self,
call_flags: GroupCallFlags,
group: impl AsArg<StringName>,
property: impl AsArg<GString>,
group: impl AsArg<StringName> + ShouldBePassedAsRef,
property: impl AsArg<GString> + ShouldBePassedAsRef,
value: &Variant,
) {
self.raw_set_group_flags(call_flags.ord() as u32, group, property, value)
}

/// Assumes notifications of `Node`. To relay those of derived constants, use [`NodeNotification::Unknown`].
pub fn notify_group(&mut self, group: impl AsArg<StringName>, notification: NodeNotification) {
pub fn notify_group(
&mut self,
group: impl AsArg<StringName> + ShouldBePassedAsRef,
notification: NodeNotification,
) {
self.raw_notify_group(group, notification.into())
}

/// Assumes notifications of `Node`. To relay those of derived constants, use [`NodeNotification::Unknown`].
pub fn notify_group_flags(
&mut self,
call_flags: GroupCallFlags,
group: impl AsArg<StringName>,
group: impl AsArg<StringName> + ShouldBePassedAsRef,
notification: NodeNotification,
) {
self.raw_notify_group_flags(call_flags.ord() as u32, group, notification.into())
Expand Down
Loading
Loading