Trait INSArray

Source
pub trait INSArray: INSObject {
    type Item: INSObject;
    type Own: Ownership;

Show 13 methods // Provided methods fn count(&self) -> usize { ... } fn object_at(&self, index: usize) -> &Self::Item { ... } fn first_object(&self) -> Option<&Self::Item> { ... } fn last_object(&self) -> Option<&Self::Item> { ... } fn object_enumerator(&self) -> NSEnumerator<'_, Self::Item> { ... } fn from_vec(vec: Vec<Id<Self::Item, Self::Own>>) -> Id<Self> { ... } fn objects_in_range(&self, range: Range<usize>) -> Vec<&Self::Item> { ... } fn to_vec(&self) -> Vec<&Self::Item> { ... } fn into_vec(array: Id<Self>) -> Vec<Id<Self::Item, Self::Own>> { ... } fn mut_object_at(&mut self, index: usize) -> &mut Self::Item where Self: INSArray<Own = Owned> { ... } fn shared_object_at(&self, index: usize) -> ShareId<Self::Item> where Self: INSArray<Own = Shared> { ... } fn from_slice(slice: &[ShareId<Self::Item>]) -> Id<Self> where Self: INSArray<Own = Shared> { ... } fn to_shared_vec(&self) -> Vec<ShareId<Self::Item>> where Self: INSArray<Own = Shared> { ... }
}

Required Associated Types§

Provided Methods§

Source

fn count(&self) -> usize

Examples found in repository?
examples/example.rs (line 20)
6fn main() {
7    // Create and compare NSObjects
8    let obj = NSObject::new();
9    println!("{:?} == {:?}? {:?}", obj, obj, obj == obj);
10
11    let obj2 = NSObject::new();
12    println!("{:?} == {:?}? {:?}", obj, obj2, obj == obj2);
13
14    // Create an NSArray from a Vec
15    let objs = vec![obj, obj2];
16    let array = NSArray::from_vec(objs);
17    for obj in array.object_enumerator() {
18        println!("{:?}", obj);
19    }
20    println!("{}", array.count());
21
22    // Turn the NSArray back into a Vec
23    let mut objs = NSArray::into_vec(array);
24    let obj = objs.pop().unwrap();
25
26    // Create an NSString from a str slice
27    let string = NSString::from_str("Hello, world!");
28    println!("{}", string.as_str());
29    let string2 = string.copy();
30    println!("{}", string2.as_str());
31
32    // Create a dictionary mapping strings to objects
33    let keys = &[&*string];
34    let vals = vec![obj];
35    let dict = NSDictionary::from_keys_and_objects(keys, vals);
36    println!("{:?}", dict.object_for(&string));
37    println!("{}", dict.count());
38}
Source

fn object_at(&self, index: usize) -> &Self::Item

Source

fn first_object(&self) -> Option<&Self::Item>

Source

fn last_object(&self) -> Option<&Self::Item>

Source

fn object_enumerator(&self) -> NSEnumerator<'_, Self::Item>

Examples found in repository?
examples/example.rs (line 17)
6fn main() {
7    // Create and compare NSObjects
8    let obj = NSObject::new();
9    println!("{:?} == {:?}? {:?}", obj, obj, obj == obj);
10
11    let obj2 = NSObject::new();
12    println!("{:?} == {:?}? {:?}", obj, obj2, obj == obj2);
13
14    // Create an NSArray from a Vec
15    let objs = vec![obj, obj2];
16    let array = NSArray::from_vec(objs);
17    for obj in array.object_enumerator() {
18        println!("{:?}", obj);
19    }
20    println!("{}", array.count());
21
22    // Turn the NSArray back into a Vec
23    let mut objs = NSArray::into_vec(array);
24    let obj = objs.pop().unwrap();
25
26    // Create an NSString from a str slice
27    let string = NSString::from_str("Hello, world!");
28    println!("{}", string.as_str());
29    let string2 = string.copy();
30    println!("{}", string2.as_str());
31
32    // Create a dictionary mapping strings to objects
33    let keys = &[&*string];
34    let vals = vec![obj];
35    let dict = NSDictionary::from_keys_and_objects(keys, vals);
36    println!("{:?}", dict.object_for(&string));
37    println!("{}", dict.count());
38}
Source

fn from_vec(vec: Vec<Id<Self::Item, Self::Own>>) -> Id<Self>

Examples found in repository?
examples/example.rs (line 16)
6fn main() {
7    // Create and compare NSObjects
8    let obj = NSObject::new();
9    println!("{:?} == {:?}? {:?}", obj, obj, obj == obj);
10
11    let obj2 = NSObject::new();
12    println!("{:?} == {:?}? {:?}", obj, obj2, obj == obj2);
13
14    // Create an NSArray from a Vec
15    let objs = vec![obj, obj2];
16    let array = NSArray::from_vec(objs);
17    for obj in array.object_enumerator() {
18        println!("{:?}", obj);
19    }
20    println!("{}", array.count());
21
22    // Turn the NSArray back into a Vec
23    let mut objs = NSArray::into_vec(array);
24    let obj = objs.pop().unwrap();
25
26    // Create an NSString from a str slice
27    let string = NSString::from_str("Hello, world!");
28    println!("{}", string.as_str());
29    let string2 = string.copy();
30    println!("{}", string2.as_str());
31
32    // Create a dictionary mapping strings to objects
33    let keys = &[&*string];
34    let vals = vec![obj];
35    let dict = NSDictionary::from_keys_and_objects(keys, vals);
36    println!("{:?}", dict.object_for(&string));
37    println!("{}", dict.count());
38}
Source

fn objects_in_range(&self, range: Range<usize>) -> Vec<&Self::Item>

Source

fn to_vec(&self) -> Vec<&Self::Item>

Source

fn into_vec(array: Id<Self>) -> Vec<Id<Self::Item, Self::Own>>

Examples found in repository?
examples/example.rs (line 23)
6fn main() {
7    // Create and compare NSObjects
8    let obj = NSObject::new();
9    println!("{:?} == {:?}? {:?}", obj, obj, obj == obj);
10
11    let obj2 = NSObject::new();
12    println!("{:?} == {:?}? {:?}", obj, obj2, obj == obj2);
13
14    // Create an NSArray from a Vec
15    let objs = vec![obj, obj2];
16    let array = NSArray::from_vec(objs);
17    for obj in array.object_enumerator() {
18        println!("{:?}", obj);
19    }
20    println!("{}", array.count());
21
22    // Turn the NSArray back into a Vec
23    let mut objs = NSArray::into_vec(array);
24    let obj = objs.pop().unwrap();
25
26    // Create an NSString from a str slice
27    let string = NSString::from_str("Hello, world!");
28    println!("{}", string.as_str());
29    let string2 = string.copy();
30    println!("{}", string2.as_str());
31
32    // Create a dictionary mapping strings to objects
33    let keys = &[&*string];
34    let vals = vec![obj];
35    let dict = NSDictionary::from_keys_and_objects(keys, vals);
36    println!("{:?}", dict.object_for(&string));
37    println!("{}", dict.count());
38}
Source

fn mut_object_at(&mut self, index: usize) -> &mut Self::Item
where Self: INSArray<Own = Owned>,

Source

fn shared_object_at(&self, index: usize) -> ShareId<Self::Item>
where Self: INSArray<Own = Shared>,

Source

fn from_slice(slice: &[ShareId<Self::Item>]) -> Id<Self>
where Self: INSArray<Own = Shared>,

Source

fn to_shared_vec(&self) -> Vec<ShareId<Self::Item>>
where Self: INSArray<Own = Shared>,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, O> INSArray for NSArray<T, O>
where T: INSObject, O: Ownership,

Source§

type Item = T

Source§

type Own = O

Source§

impl<T, O> INSArray for NSMutableArray<T, O>
where T: INSObject, O: Ownership,

Source§

type Item = T

Source§

type Own = O