Trait INSDictionary

Source
pub trait INSDictionary: INSObject {
    type Key: INSObject;
    type Value: INSObject;
    type Own: Ownership;

    // Provided methods
    fn count(&self) -> usize { ... }
    fn object_for(&self, key: &Self::Key) -> Option<&Self::Value> { ... }
    fn keys(&self) -> Vec<&Self::Key> { ... }
    fn values(&self) -> Vec<&Self::Value> { ... }
    fn keys_and_objects(&self) -> (Vec<&Self::Key>, Vec<&Self::Value>) { ... }
    fn key_enumerator(&self) -> NSEnumerator<'_, Self::Key>  { ... }
    fn object_enumerator(&self) -> NSEnumerator<'_, Self::Value>  { ... }
    fn keys_array(&self) -> Id<NSSharedArray<Self::Key>> { ... }
    fn from_keys_and_objects<T>(
        keys: &[&T],
        vals: Vec<Id<Self::Value, Self::Own>>,
    ) -> Id<Self>
       where T: INSCopying<Output = Self::Key> { ... }
    fn into_values_array(dict: Id<Self>) -> Id<NSArray<Self::Value, Self::Own>> { ... }
}

Required Associated Types§

Provided Methods§

Source

fn count(&self) -> usize

Examples found in repository?
examples/example.rs (line 37)
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_for(&self, key: &Self::Key) -> Option<&Self::Value>

Examples found in repository?
examples/example.rs (line 36)
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 keys(&self) -> Vec<&Self::Key>

Source

fn values(&self) -> Vec<&Self::Value>

Source

fn keys_and_objects(&self) -> (Vec<&Self::Key>, Vec<&Self::Value>)

Source

fn key_enumerator(&self) -> NSEnumerator<'_, Self::Key>

Source

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

Source

fn keys_array(&self) -> Id<NSSharedArray<Self::Key>>

Source

fn from_keys_and_objects<T>( keys: &[&T], vals: Vec<Id<Self::Value, Self::Own>>, ) -> Id<Self>
where T: INSCopying<Output = Self::Key>,

Examples found in repository?
examples/example.rs (line 35)
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 into_values_array(dict: Id<Self>) -> Id<NSArray<Self::Value, Self::Own>>

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<K, V> INSDictionary for NSDictionary<K, V>
where K: INSObject, V: INSObject,