@@ -215,15 +215,15 @@ impl<T: GodotType> Array<T> {
215
215
216
216
#[ doc( hidden) ]
217
217
pub fn as_inner ( & self ) -> inner:: InnerArray {
218
- // SAFETY: The memory layout of `TypedArray <T>` does not depend on `T`.
218
+ // SAFETY: The memory layout of `Array <T>` does not depend on `T`.
219
219
inner:: InnerArray :: from_outer_typed ( self )
220
220
}
221
221
222
222
/// Changes the generic type on this array, without changing its contents. Needed for API
223
223
/// functions that return a variant array even though we know its type, and for API functions
224
224
/// that take a variant array even though we want to pass a typed one.
225
225
///
226
- /// This is marked `unsafe` since it can be used to break the invariant that a `TypedArray <T>`
226
+ /// This is marked `unsafe` since it can be used to break the invariant that a `Array <T>`
227
227
/// always holds a Godot array whose runtime type is `T`.
228
228
///
229
229
/// # Safety
@@ -236,7 +236,7 @@ impl<T: GodotType> Array<T> {
236
236
/// In the current implementation, both cases will produce a panic rather than undefined
237
237
/// behavior, but this should not be relied upon.
238
238
unsafe fn assume_type < U : GodotType > ( self ) -> Array < U > {
239
- // SAFETY: The memory layout of `TypedArray <T>` does not depend on `T`.
239
+ // SAFETY: The memory layout of `Array <T>` does not depend on `T`.
240
240
unsafe { std:: mem:: transmute ( self ) }
241
241
}
242
242
}
@@ -276,7 +276,7 @@ impl<T: GodotType> Array<T> {
276
276
///
277
277
/// If specified, `step` is the relative index between source elements. It can be negative,
278
278
/// in which case `begin` must be higher than `end`. For example,
279
- /// `TypedArray ::from(&[0, 1, 2, 3, 4, 5]).slice(5, 1, -2)` returns `[5, 3]`.
279
+ /// `Array ::from(&[0, 1, 2, 3, 4, 5]).slice(5, 1, -2)` returns `[5, 3]`.
280
280
///
281
281
/// Array elements are copied to the slice, but any reference types (such as `Array`,
282
282
/// `Dictionary` and `Object`) will still refer to the same value. To create a deep copy, use
@@ -292,7 +292,7 @@ impl<T: GodotType> Array<T> {
292
292
///
293
293
/// If specified, `step` is the relative index between source elements. It can be negative,
294
294
/// in which case `begin` must be higher than `end`. For example,
295
- /// `TypedArray ::from(&[0, 1, 2, 3, 4, 5]).slice(5, 1, -2)` returns `[5, 3]`.
295
+ /// `Array ::from(&[0, 1, 2, 3, 4, 5]).slice(5, 1, -2)` returns `[5, 3]`.
296
296
///
297
297
/// All nested arrays and dictionaries are duplicated and will not be shared with the original
298
298
/// array. Note that any `Object`-derived elements will still be shallow copied. To create a
@@ -576,7 +576,7 @@ impl<T: GodotType + ToGodot> Array<T> {
576
576
let len = self . len ( ) ;
577
577
assert ! (
578
578
index <= len,
579
- "TypedArray insertion index {index} is out of bounds: length is {len}" ,
579
+ "Array insertion index {index} is out of bounds: length is {len}" ,
580
580
) ;
581
581
self . as_inner ( ) . insert ( to_i64 ( index) , value. to_variant ( ) ) ;
582
582
}
@@ -604,9 +604,9 @@ impl<T: GodotType + ToGodot> Array<T> {
604
604
// but `[NAN] == [NAN]` is `true`. If they decide to make all NaNs equal, we can implement `Eq` and
605
605
// `Ord`; if they decide to make all NaNs unequal, we can remove this comment.
606
606
//
607
- // impl<T> Eq for TypedArray <T> {}
607
+ // impl<T> Eq for Array <T> {}
608
608
//
609
- // impl<T> Ord for TypedArray <T> {
609
+ // impl<T> Ord for Array <T> {
610
610
// ...
611
611
// }
612
612
@@ -1063,3 +1063,61 @@ impl fmt::Debug for TypeInfo {
1063
1063
write ! ( f, "{:?}{}" , self . variant_type, class_str)
1064
1064
}
1065
1065
}
1066
+
1067
+ #[ cfg( feature = "serde" ) ]
1068
+ mod serialize {
1069
+ use super :: * ;
1070
+ use serde:: {
1071
+ de:: { SeqAccess , Visitor } ,
1072
+ ser:: SerializeSeq ,
1073
+ Deserialize , Deserializer , Serialize , Serializer ,
1074
+ } ;
1075
+ use std:: marker:: PhantomData ;
1076
+
1077
+ impl < T : Serialize + GodotType > Serialize for Array < T > {
1078
+ #[ inline]
1079
+ fn serialize < S > ( & self , ser : S ) -> Result < <S as Serializer >:: Ok , <S as Serializer >:: Error >
1080
+ where
1081
+ S : Serializer ,
1082
+ {
1083
+ let mut ser = ser. serialize_seq ( Some ( self . len ( ) ) ) ?;
1084
+ for e in self . iter_shared ( ) {
1085
+ ser. serialize_element ( & e) ?
1086
+ }
1087
+ ser. end ( )
1088
+ }
1089
+ }
1090
+
1091
+ impl < ' de , T : Deserialize < ' de > + GodotType > Deserialize < ' de > for Array < T > {
1092
+ #[ inline]
1093
+ fn deserialize < D > ( deserializer : D ) -> Result < Self , <D as Deserializer < ' de > >:: Error >
1094
+ where
1095
+ D : Deserializer < ' de > ,
1096
+ {
1097
+ struct ArrayVisitor < T > ( PhantomData < T > ) ;
1098
+ impl < ' de , T : Deserialize < ' de > + GodotType > Visitor < ' de > for ArrayVisitor < T > {
1099
+ type Value = Array < T > ;
1100
+
1101
+ fn expecting ( & self , formatter : & mut std:: fmt:: Formatter ) -> fmt:: Result {
1102
+ formatter. write_str ( std:: any:: type_name :: < Self :: Value > ( ) )
1103
+ }
1104
+
1105
+ fn visit_seq < A > (
1106
+ self ,
1107
+ mut seq : A ,
1108
+ ) -> Result < Self :: Value , <A as SeqAccess < ' de > >:: Error >
1109
+ where
1110
+ A : SeqAccess < ' de > ,
1111
+ {
1112
+ let mut vec = seq. size_hint ( ) . map_or_else ( Vec :: new, Vec :: with_capacity) ;
1113
+ while let Some ( val) = seq. next_element :: < T > ( ) ? {
1114
+ vec. push ( val) ;
1115
+ }
1116
+ Ok ( Self :: Value :: from ( vec. as_slice ( ) ) )
1117
+ }
1118
+ }
1119
+
1120
+ deserializer. deserialize_seq ( ArrayVisitor :: < T > ( PhantomData ) )
1121
+ }
1122
+ }
1123
+ }
0 commit comments