@@ -57,14 +57,13 @@ unsafe fn from_refs<T: Message + ?Sized>(cls: &Class, refs: &[&T]) -> *mut Objec
57
57
}
58
58
}
59
59
60
- impl < T : Message , O : Ownership > NSArray < T , O > {
60
+ impl < T : Message > NSArray < T , Shared > {
61
61
unsafe_def_fn ! {
62
- /// The `NSArray` itself (length and number of items) is always immutable,
63
- /// but we would like to know when we're the only owner of the array, to
64
- /// allow mutation of the array's items.
65
- pub fn new -> O ;
62
+ pub fn new -> Shared ;
66
63
}
64
+ }
67
65
66
+ impl < T : Message , O : Ownership > NSArray < T , O > {
68
67
#[ doc( alias = "count" ) ]
69
68
pub fn len ( & self ) -> usize {
70
69
unsafe { msg_send ! [ self , count] }
@@ -103,6 +102,9 @@ impl<T: Message, O: Ownership> NSArray<T, O> {
103
102
}
104
103
}
105
104
105
+ // The `NSArray` itself (length and number of items) is always immutable,
106
+ // but we would like to know when we're the only owner of the array, to
107
+ // allow mutation of the array's items.
106
108
pub fn from_vec ( vec : Vec < Id < T , O > > ) -> Id < Self , O > {
107
109
unsafe { Id :: new ( from_refs ( Self :: class ( ) , vec. as_slice_ref ( ) ) . cast ( ) ) . unwrap ( ) }
108
110
}
@@ -204,8 +206,8 @@ impl<T: Message, O: Ownership> Index<usize> for NSArray<T, O> {
204
206
}
205
207
}
206
208
207
- impl < T : Message , O : Ownership > DefaultId for NSArray < T , O > {
208
- type Ownership = O ;
209
+ impl < T : Message > DefaultId for NSArray < T , Shared > {
210
+ type Ownership = Shared ;
209
211
210
212
#[ inline]
211
213
fn default_id ( ) -> Id < Self , Self :: Ownership > {
@@ -407,9 +409,15 @@ mod tests {
407
409
unsafe { msg_send ! [ obj, retainCount] }
408
410
}
409
411
412
+ #[ test]
413
+ fn test_two_empty ( ) {
414
+ let _empty_array1 = NSArray :: < NSObject , _ > :: new ( ) ;
415
+ let _empty_array2 = NSArray :: < NSObject , _ > :: new ( ) ;
416
+ }
417
+
410
418
#[ test]
411
419
fn test_len ( ) {
412
- let empty_array = NSArray :: < NSObject , Owned > :: new ( ) ;
420
+ let empty_array = NSArray :: < NSObject , _ > :: new ( ) ;
413
421
assert_eq ! ( empty_array. len( ) , 0 ) ;
414
422
415
423
let array = sample_array ( 4 ) ;
@@ -450,7 +458,7 @@ mod tests {
450
458
assert_eq ! ( array. first( ) , array. get( 0 ) ) ;
451
459
assert_eq ! ( array. last( ) , array. get( 3 ) ) ;
452
460
453
- let empty_array = <NSArray < NSObject , Owned > >:: new ( ) ;
461
+ let empty_array = <NSArray < NSObject , Shared > >:: new ( ) ;
454
462
assert ! ( empty_array. first( ) . is_none( ) ) ;
455
463
assert ! ( empty_array. last( ) . is_none( ) ) ;
456
464
}
0 commit comments