File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
gdnative-core/src/core_types Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,18 @@ impl<Access: ThreadAccess> VariantArray<Access> {
157
157
}
158
158
}
159
159
160
+ /// Create a deep copy of the array.
161
+ ///
162
+ /// This creates a new array and is **not** a cheap reference count
163
+ /// increment.
164
+ #[ inline]
165
+ pub fn duplicate_deep ( & self ) -> VariantArray < Unique > {
166
+ unsafe {
167
+ let sys = ( get_api ( ) . godot_array_duplicate ) ( self . sys ( ) , true ) ;
168
+ VariantArray :: < Unique > :: from_sys ( sys)
169
+ }
170
+ }
171
+
160
172
/// Returns an iterator through all values in the `VariantArray`.
161
173
///
162
174
/// `VariantArray` is reference-counted and have interior mutability in Rust parlance.
@@ -647,6 +659,18 @@ godot_test!(test_array {
647
659
& [ 42 , 1337 , 512 ] ,
648
660
array3. iter( ) . map( |v| v. try_to_i64( ) . unwrap( ) ) . collect:: <Vec <_>>( ) . as_slice( ) ,
649
661
) ;
662
+
663
+ let array4 = VariantArray :: new( ) ; // []
664
+ let array5 = VariantArray :: new( ) ; // []
665
+ array4. push( & foo) ; // [&foo]
666
+ array4. push( & bar) ; // [&foo, &bar]
667
+ array5. push( array4) ; // [[&foo, &bar]]
668
+
669
+ let array6 = array5. duplicate_deep( ) ; // [[&foo, &bar]]
670
+ unsafe { array5. get( 0 ) . to_array( ) . assume_unique( ) . pop( ) ; } // [[&foo]]
671
+
672
+ assert!( !array5. get( 0 ) . to_array( ) . contains( & bar) ) ;
673
+ assert!( array6. get( 0 ) . to_array( ) . contains( & bar) ) ;
650
674
} ) ;
651
675
652
676
godot_test ! (
You can’t perform that action at this time.
0 commit comments