File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -626,6 +626,19 @@ impl<T: GodotClass> ToVariant for Gd<T> {
626
626
}
627
627
}
628
628
629
+ impl < T : GodotClass > PartialEq for Gd < T > {
630
+ /// ⚠️ Returns whether two `Gd` pointers point to the same object.
631
+ ///
632
+ /// # Panics
633
+ /// When `self` or `other` is dead.
634
+ fn eq ( & self , other : & Self ) -> bool {
635
+ // Panics when one is dead
636
+ self . instance_id ( ) == other. instance_id ( )
637
+ }
638
+ }
639
+
640
+ impl < T : GodotClass > Eq for Gd < T > { }
641
+
629
642
impl < T > Display for Gd < T >
630
643
where
631
644
T : GodotClass < Declarer = dom:: EngineDomain > ,
Original file line number Diff line number Diff line change @@ -161,6 +161,35 @@ fn object_from_instance_id_unrelated_type() {
161
161
node. free ( ) ;
162
162
}
163
163
164
+ #[ itest]
165
+ fn object_user_eq ( ) {
166
+ let value: i16 = 17943 ;
167
+ let a = ObjPayload { value } ;
168
+ let b = ObjPayload { value } ;
169
+
170
+ let a1 = Gd :: new ( a) ;
171
+ let a2 = a1. share ( ) ;
172
+ let b1 = Gd :: new ( b) ;
173
+
174
+ assert_eq ! ( a1, a2) ;
175
+ assert_ne ! ( a1, b1) ;
176
+ assert_ne ! ( a2, b1) ;
177
+ }
178
+
179
+ #[ itest]
180
+ fn object_engine_eq ( ) {
181
+ let a1 = Node3D :: new_alloc ( ) ;
182
+ let a2 = a1. share ( ) ;
183
+ let b1 = Node3D :: new_alloc ( ) ;
184
+
185
+ assert_eq ! ( a1, a2) ;
186
+ assert_ne ! ( a1, b1) ;
187
+ assert_ne ! ( a2, b1) ;
188
+
189
+ a1. free ( ) ;
190
+ b1. free ( ) ;
191
+ }
192
+
164
193
#[ itest]
165
194
fn object_user_convert_variant ( ) {
166
195
let value: i16 = 17943 ;
You can’t perform that action at this time.
0 commit comments