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 } ;
138use std:: fmt;
149use 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`].
10501052pub 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" ) ]
12251181mod serialize {
12261182 use super :: * ;
0 commit comments