@@ -174,6 +174,26 @@ object!(
174
174
}
175
175
) ;
176
176
177
+ // SAFETY: Same as Id<T, O> (which is what NSArray effectively stores).
178
+ //
179
+ // The `PhantomData` can't get these impls to display in the docs.
180
+ //
181
+ // TODO: Properly verify this
182
+ unsafe impl < T : Sync + Send > Sync for NSArray < T , Shared > { }
183
+ unsafe impl < T : Sync + Send > Send for NSArray < T , Shared > { }
184
+ unsafe impl < T : Sync > Sync for NSArray < T , Owned > { }
185
+ unsafe impl < T : Send > Send for NSArray < T , Owned > { }
186
+
187
+ /// ```compile_fail
188
+ /// use objc2::rc::Shared;
189
+ /// use objc2::runtime::Object;
190
+ /// use objc2_foundation::NSArray;
191
+ /// fn needs_send_sync<T: Send + Sync>() {}
192
+ /// needs_send_sync::<NSArray<Object, Shared>>();
193
+ /// ```
194
+ #[ cfg( doctest) ]
195
+ pub struct NSArrayWithObjectNotSendSync ;
196
+
177
197
unsafe impl < T : INSObject , O : Ownership > INSArray for NSArray < T , O > {
178
198
/// The `NSArray` itself (length and number of items) is always immutable,
179
199
/// but we would like to know when we're the only owner of the array, to
@@ -319,6 +339,14 @@ object!(
319
339
}
320
340
) ;
321
341
342
+ // SAFETY: Same as NSArray.
343
+ //
344
+ // TODO: Properly verify this
345
+ unsafe impl < T : Sync + Send > Sync for NSMutableArray < T , Shared > { }
346
+ unsafe impl < T : Sync + Send > Send for NSMutableArray < T , Shared > { }
347
+ unsafe impl < T : Sync > Sync for NSMutableArray < T , Owned > { }
348
+ unsafe impl < T : Send > Send for NSMutableArray < T , Owned > { }
349
+
322
350
unsafe impl < T : INSObject , O : Ownership > INSArray for NSMutableArray < T , O > {
323
351
type Ownership = Owned ;
324
352
type Item = T ;
@@ -540,4 +568,14 @@ mod tests {
540
568
assert_eq ! ( strings[ 1 ] . as_str( pool) , "hello" ) ;
541
569
} ) ;
542
570
}
571
+
572
+ #[ test]
573
+ fn test_send_sync ( ) {
574
+ fn assert_send_sync < T : Send + Sync > ( ) { }
575
+
576
+ assert_send_sync :: < NSArray < NSString , Shared > > ( ) ;
577
+ assert_send_sync :: < NSMutableArray < NSString , Shared > > ( ) ;
578
+ assert_send_sync :: < Id < NSArray < NSString , Shared > , Shared > > ( ) ;
579
+ assert_send_sync :: < Id < NSMutableArray < NSString , Shared > , Owned > > ( ) ;
580
+ }
543
581
}
0 commit comments