Skip to content

Commit 51e2e17

Browse files
committed
Add FfiArg to remove invalid states in AsArg::into_arg()
1 parent aa713bd commit 51e2e17

File tree

3 files changed

+123
-121
lines changed

3 files changed

+123
-121
lines changed

godot-core/src/meta/args/as_arg.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::ffi::CStr;
1010
use crate::builtin::{GString, NodePath, StringName, Variant};
1111
use crate::meta::sealed::Sealed;
1212
use crate::meta::traits::{GodotFfiVariant, GodotNullableFfi};
13-
use crate::meta::{CowArg, GodotType, ObjectArg, ToGodot};
13+
use crate::meta::{CowArg, FfiArg, GodotType, ObjectArg, ToGodot};
1414
use crate::obj::{bounds, Bounds, DynGd, Gd, GodotClass, Inherits};
1515

1616
/// Implicit conversions for arguments passed to Godot APIs.
@@ -97,13 +97,14 @@ where
9797

9898
/// FFI-optimized argument conversion that may use `FfiObject` when beneficial.
9999
///
100-
/// Defaults to calling `into_arg()`, which always works, but might be an `Owned` for a conservative approach (e.g. object upcast).
100+
/// Defaults to calling `into_arg()` and wrapping in `FfiArg::Cow()`, which always works, but might be an `Owned` for a conservative
101+
/// approach (e.g. object upcast).
101102
#[doc(hidden)]
102-
fn into_ffi_arg<'arg>(self) -> CowArg<'arg, T>
103+
fn into_ffi_arg<'arg>(self) -> FfiArg<'arg, T>
103104
where
104105
Self: 'arg,
105106
{
106-
self.into_arg()
107+
FfiArg::Cow(self.into_arg())
107108
}
108109
}
109110

@@ -157,12 +158,12 @@ where
157158
}
158159
}
159160

160-
fn into_ffi_arg<'arg>(self) -> CowArg<'arg, Gd<Base>>
161+
fn into_ffi_arg<'arg>(self) -> FfiArg<'arg, Gd<Base>>
161162
where
162163
Self: 'arg,
163164
{
164165
let arg = ObjectArg::from_gd(self);
165-
CowArg::FfiObject(arg)
166+
FfiArg::FfiObject(arg)
166167
}
167168
}
168169

@@ -189,12 +190,12 @@ where
189190
}
190191
}
191192

192-
fn into_ffi_arg<'arg>(self) -> CowArg<'arg, DynGd<Base, D>>
193+
fn into_ffi_arg<'arg>(self) -> FfiArg<'arg, DynGd<Base, D>>
193194
where
194195
Self: 'arg,
195196
{
196197
let arg = ObjectArg::from_gd(self);
197-
CowArg::FfiObject(arg)
198+
FfiArg::FfiObject(arg)
198199
}
199200
}
200201

@@ -213,7 +214,7 @@ where
213214
AsArg::into_arg(gd_ref)
214215
}
215216

216-
fn into_ffi_arg<'arg>(self) -> CowArg<'arg, Gd<Base>>
217+
fn into_ffi_arg<'arg>(self) -> FfiArg<'arg, Gd<Base>>
217218
where
218219
Self: 'arg,
219220
{
@@ -242,12 +243,12 @@ where
242243
}
243244
}
244245

245-
fn into_ffi_arg<'arg>(self) -> CowArg<'arg, Option<Gd<Base>>>
246+
fn into_ffi_arg<'arg>(self) -> FfiArg<'arg, Option<Gd<Base>>>
246247
where
247248
Self: 'arg,
248249
{
249250
let arg = ObjectArg::from_option_gd(self);
250-
CowArg::FfiObject(arg)
251+
FfiArg::FfiObject(arg)
251252
}
252253
}
253254

@@ -265,12 +266,12 @@ where
265266
CowArg::Owned(Some(self.clone().upcast::<Base>()))
266267
}
267268

268-
fn into_ffi_arg<'arg>(self) -> CowArg<'arg, Option<Gd<Base>>>
269+
fn into_ffi_arg<'arg>(self) -> FfiArg<'arg, Option<Gd<Base>>>
269270
where
270271
Self: 'arg,
271272
{
272273
let arg = ObjectArg::from_gd(self);
273-
CowArg::FfiObject(arg)
274+
FfiArg::FfiObject(arg)
274275
}
275276
}
276277

@@ -289,7 +290,7 @@ where
289290
AsArg::into_arg(gd_ref)
290291
}
291292

292-
fn into_ffi_arg<'arg>(self) -> CowArg<'arg, Option<Gd<Base>>>
293+
fn into_ffi_arg<'arg>(self) -> FfiArg<'arg, Option<Gd<Base>>>
293294
where
294295
Self: 'arg,
295296
{

0 commit comments

Comments
 (0)