Skip to content

Commit 7ebd5ec

Browse files
authored
Merge pull request #735 from godot-rust/feature/streamlined-modules-4
Streamline modules - part IV: `godot::meta`, `godot::builtin::iter`
2 parents 3c7173c + da2355d commit 7ebd5ec

File tree

106 files changed

+1494
-1405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1494
-1405
lines changed

godot-codegen/src/generator/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn make_special_builtin_methods(class_name: &TyName, _ctx: &Context) -> TokenStr
150150
quote! {
151151
pub fn from_outer_typed<T>(outer: &Array<T>) -> Self
152152
where
153-
T: crate::builtin::meta::ArrayElement
153+
T: crate::meta::ArrayElement
154154
{
155155
Self {
156156
_outer_lifetime: std::marker::PhantomData,

godot-codegen/src/generator/enums.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,20 @@ pub fn make_enum_definition_with(
107107
#index_enum_impl
108108
#bitwise_impls
109109

110-
impl crate::builtin::meta::GodotConvert for #name {
110+
impl crate::meta::GodotConvert for #name {
111111
type Via = #ord_type;
112112
}
113113

114-
impl crate::builtin::meta::ToGodot for #name {
114+
impl crate::meta::ToGodot for #name {
115115
fn to_godot(&self) -> Self::Via {
116116
<Self as #engine_trait>::ord(*self)
117117
}
118118
}
119119

120-
impl crate::builtin::meta::FromGodot for #name {
121-
fn try_from_godot(via: Self::Via) -> std::result::Result<Self, crate::builtin::meta::ConvertError> {
120+
impl crate::meta::FromGodot for #name {
121+
fn try_from_godot(via: Self::Via) -> std::result::Result<Self, crate::meta::error::ConvertError> {
122122
<Self as #engine_trait>::try_from_ord(via)
123-
.ok_or_else(|| crate::builtin::meta::FromGodotError::InvalidEnum.into_error(via))
123+
.ok_or_else(|| crate::meta::error::FromGodotError::InvalidEnum.into_error(via))
124124
}
125125
}
126126
}

godot-codegen/src/generator/native_structures.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn make_native_structure(
7171
// mod re_export needed, because class should not appear inside the file module, and we can't re-export private struct as pub
7272
let tokens = quote! {
7373
#imports
74-
use crate::builtin::meta::{GodotConvert, FromGodot, ToGodot};
74+
use crate::meta::{GodotConvert, FromGodot, ToGodot};
7575

7676
/// Native structure; can be passed via pointer in APIs that are not exposed to GDScript.
7777
///
@@ -93,7 +93,7 @@ fn make_native_structure(
9393
}
9494

9595
impl FromGodot for *mut #class_name {
96-
fn try_from_godot(via: Self::Via) -> Result<Self, crate::builtin::meta::ConvertError> {
96+
fn try_from_godot(via: Self::Via) -> Result<Self, crate::meta::error::ConvertError> {
9797
Ok(via as Self)
9898
}
9999
}
@@ -109,7 +109,7 @@ fn make_native_structure(
109109
}
110110

111111
impl FromGodot for *const #class_name {
112-
fn try_from_godot(via: Self::Via) -> Result<Self, crate::builtin::meta::ConvertError> {
112+
fn try_from_godot(via: Self::Via) -> Result<Self, crate::meta::error::ConvertError> {
113113
Ok(via as Self)
114114
}
115115
}

godot-codegen/src/generator/virtual_traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn make_special_virtual_methods(notification_enum_name: &Ident) -> TokenStream {
114114
/// See also in Godot docs:
115115
/// * [`Object::_get_property_list`](https://docs.godotengine.org/en/latest/classes/class_object.html#class-object-private-method-get-property-list)
116116
#[cfg(since_api = "4.3")]
117-
fn get_property_list(&mut self) -> Vec<crate::builtin::meta::PropertyInfo> {
117+
fn get_property_list(&mut self) -> Vec<crate::meta::PropertyInfo> {
118118
unimplemented!()
119119
}
120120

godot-codegen/src/models/domain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl FnReturn {
560560

561561
pub fn call_result_decl(&self) -> TokenStream {
562562
let ret = self.type_tokens();
563-
quote! { -> Result<#ret, crate::builtin::meta::CallError> }
563+
quote! { -> Result<#ret, crate::meta::error::CallError> }
564564
}
565565
}
566566

godot-codegen/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn make_imports() -> TokenStream {
2323
quote! {
2424
use godot_ffi as sys;
2525
use crate::builtin::*;
26-
use crate::builtin::meta::{ClassName, PtrcallSignatureTuple, VarcallSignatureTuple};
26+
use crate::meta::{ClassName, PtrcallSignatureTuple, VarcallSignatureTuple};
2727
use crate::classes::native::*;
2828
use crate::classes::Object;
2929
use crate::obj::Gd;

godot-core/src/builtin/aabb.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use sys::{ffi_methods, GodotFfi};
1111
use crate::builtin::math::ApproxEq;
1212
use crate::builtin::{real, Plane, Vector3, Vector3Axis};
1313

14-
use super::meta::impl_godot_as_self;
15-
1614
/// Axis-aligned bounding box in 3D space.
1715
///
1816
/// `Aabb` consists of a position, a size, and several utility functions. It is typically used for
@@ -406,7 +404,7 @@ unsafe impl GodotFfi for Aabb {
406404
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
407405
}
408406

409-
impl_godot_as_self!(Aabb);
407+
crate::meta::impl_godot_as_self!(Aabb);
410408

411409
impl ApproxEq for Aabb {
412410
/// Returns `true` if the two `Aabb`s are approximately equal, by calling `is_equal_approx` on

godot-core/src/builtin/basis.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use std::cmp::Ordering;
1515
use std::fmt::Display;
1616
use std::ops::{Mul, MulAssign};
1717

18-
use super::meta::impl_godot_as_self;
19-
2018
/// A 3x3 matrix, typically used as an orthogonal basis for [`Transform3D`](crate::builtin::Transform3D).
2119
///
2220
/// Indexing into a `Basis` is done in row-major order. So `mat[1]` would return the first *row* and not
@@ -604,7 +602,7 @@ unsafe impl GodotFfi for Basis {
604602
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
605603
}
606604

607-
impl_godot_as_self!(Basis);
605+
crate::meta::impl_godot_as_self!(Basis);
608606

609607
#[cfg(test)]
610608
mod test {

godot-core/src/builtin/callable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
use godot_ffi as sys;
99

10-
use crate::builtin::meta::{impl_godot_as_self, GodotType, ToGodot};
1110
use crate::builtin::{inner, StringName, Variant, VariantArray};
1211
use crate::classes::Object;
12+
use crate::meta::{GodotType, ToGodot};
1313
use crate::obj::bounds::DynMemory;
1414
use crate::obj::Bounds;
1515
use crate::obj::{Gd, GodotClass, InstanceId};
@@ -310,7 +310,7 @@ unsafe impl GodotFfi for Callable {
310310
}
311311
}
312312

313-
impl_godot_as_self!(Callable);
313+
crate::meta::impl_godot_as_self!(Callable);
314314

315315
impl fmt::Debug for Callable {
316316
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -391,7 +391,7 @@ mod custom_callable {
391391
let c: &mut C = CallableUserdata::inner_from_raw(callable_userdata);
392392

393393
let result = c.invoke(arg_refs);
394-
crate::builtin::meta::varcall_return_checked(result, r_return, r_error);
394+
crate::meta::varcall_return_checked(result, r_return, r_error);
395395
}
396396

397397
pub unsafe extern "C" fn rust_callable_call_fn<F>(
@@ -408,7 +408,7 @@ mod custom_callable {
408408
let w: &mut FnWrapper<F> = CallableUserdata::inner_from_raw(callable_userdata);
409409

410410
let result = (w.rust_function)(arg_refs);
411-
crate::builtin::meta::varcall_return_checked(result, r_return, r_error);
411+
crate::meta::varcall_return_checked(result, r_return, r_error);
412412
}
413413

414414
pub unsafe extern "C" fn rust_callable_destroy<T>(callable_userdata: *mut std::ffi::c_void) {

godot-core/src/builtin/array.rs renamed to godot-core/src/builtin/collections/array.rs

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8-
use godot_ffi as sys;
9-
10-
use crate::builtin::*;
11-
use crate::obj::EngineEnum;
12-
use crate::property::{builtin_type_string, Export, PropertyHintInfo, TypeStringHint, Var};
138
use std::fmt;
149
use std::marker::PhantomData;
15-
use sys::{ffi_methods, interface_fn, GodotFfi};
1610

17-
use super::meta::{
18-
ArrayElement, ConvertError, FromGodot, FromGodotError, FromVariantError, GodotConvert,
19-
GodotFfiVariant, GodotType, ToGodot,
11+
use crate::builtin::*;
12+
use crate::meta::error::{ConvertError, FromGodotError, FromVariantError};
13+
use crate::meta::{
14+
ArrayElement, ArrayTypeInfo, FromGodot, GodotConvert, GodotFfiVariant, GodotType, ToGodot,
15+
};
16+
use crate::obj::EngineEnum;
17+
use crate::registry::property::{
18+
builtin_type_string, Export, PropertyHintInfo, TypeStringHint, Var,
2019
};
20+
use godot_ffi as sys;
21+
use sys::{ffi_methods, interface_fn, GodotFfi};
2122

2223
/// Godot's `Array` type.
2324
///
@@ -682,13 +683,13 @@ impl<T: ArrayElement> Array<T> {
682683
}
683684

684685
/// Returns the runtime type info of this array.
685-
fn type_info(&self) -> TypeInfo {
686+
fn type_info(&self) -> ArrayTypeInfo {
686687
let variant_type = VariantType::from_sys(
687688
self.as_inner().get_typed_builtin() as sys::GDExtensionVariantType
688689
);
689690
let class_name = self.as_inner().get_typed_class_name();
690691

691-
TypeInfo {
692+
ArrayTypeInfo {
692693
variant_type,
693694
class_name,
694695
}
@@ -697,7 +698,7 @@ impl<T: ArrayElement> Array<T> {
697698
/// Checks that the inner array has the correct type set on it for storing elements of type `T`.
698699
fn with_checked_type(self) -> Result<Self, ConvertError> {
699700
let self_ty = self.type_info();
700-
let target_ty = TypeInfo::of::<T>();
701+
let target_ty = ArrayTypeInfo::of::<T>();
701702

702703
if self_ty == target_ty {
703704
Ok(self)
@@ -719,7 +720,7 @@ impl<T: ArrayElement> Array<T> {
719720
debug_assert!(self.is_empty());
720721
debug_assert!(!self.type_info().is_typed());
721722

722-
let type_info = TypeInfo::of::<T>();
723+
let type_info = ArrayTypeInfo::of::<T>();
723724
if type_info.is_typed() {
724725
let script = Variant::nil();
725726

@@ -1047,6 +1048,7 @@ impl<T: ArrayElement + FromGodot> From<&Array<T>> for Vec<T> {
10471048

10481049
// ----------------------------------------------------------------------------------------------------------------------------------------------
10491050

1051+
/// An iterator over typed elements of an [`Array`].
10501052
pub struct Iter<'a, T: ArrayElement> {
10511053
array: &'a Array<T>,
10521054
next_idx: usize,
@@ -1163,7 +1165,7 @@ macro_rules! varray {
11631165
// Note: use to_variant() and not Variant::from(), as that works with both references and values
11641166
($($elements:expr),* $(,)?) => {
11651167
{
1166-
use $crate::builtin::meta::ToGodot as _;
1168+
use $crate::meta::ToGodot as _;
11671169
let mut array = $crate::builtin::VariantArray::default();
11681170
$(
11691171
array.push($elements.to_variant());
@@ -1175,52 +1177,6 @@ macro_rules! varray {
11751177

11761178
// ----------------------------------------------------------------------------------------------------------------------------------------------
11771179

1178-
/// Represents the type information of a Godot array. See
1179-
/// [`set_typed`](https://docs.godotengine.org/en/latest/classes/class_array.html#class-array-method-set-typed).
1180-
///
1181-
/// We ignore the `script` parameter because it has no impact on typing in Godot.
1182-
#[derive(Eq, PartialEq)]
1183-
pub(crate) struct TypeInfo {
1184-
variant_type: VariantType,
1185-
1186-
/// Not a `ClassName` because some values come from Godot engine API.
1187-
class_name: StringName,
1188-
}
1189-
1190-
impl TypeInfo {
1191-
fn of<T: GodotType>() -> Self {
1192-
Self {
1193-
variant_type: <T::Via as GodotType>::Ffi::variant_type(),
1194-
class_name: T::Via::class_name().to_string_name(),
1195-
}
1196-
}
1197-
1198-
pub fn is_typed(&self) -> bool {
1199-
self.variant_type != VariantType::NIL
1200-
}
1201-
1202-
pub fn variant_type(&self) -> VariantType {
1203-
self.variant_type
1204-
}
1205-
1206-
pub fn class_name(&self) -> &StringName {
1207-
&self.class_name
1208-
}
1209-
}
1210-
1211-
impl fmt::Debug for TypeInfo {
1212-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1213-
let class = self.class_name.to_string();
1214-
let class_str = if class.is_empty() {
1215-
String::new()
1216-
} else {
1217-
format!(" (class={class})")
1218-
};
1219-
1220-
write!(f, "{:?}{}", self.variant_type, class_str)
1221-
}
1222-
}
1223-
12241180
#[cfg(feature = "serde")]
12251181
mod serialize {
12261182
use super::*;

0 commit comments

Comments
 (0)