rust_macios/foundation/
ns_enumerator.rs

1use std::marker::PhantomData;
2
3use objc::{msg_send, sel, sel_impl};
4
5use crate::{
6    object,
7    objective_c_runtime::traits::{FromId, PNSObject},
8};
9
10use super::NSArray;
11
12object! {
13    /// An abstract class whose subclasses enumerate collections of objects, such as arrays and dictionaries.
14    unsafe pub struct NSEnumerator<ObjectType> {
15        marker: PhantomData<ObjectType>,
16    }
17}
18
19/// An abstract class whose subclasses enumerate collections of objects, such as arrays and dictionaries.
20pub trait INSEnumerator<ObjectType>: PNSObject
21where
22    ObjectType: PNSObject + FromId,
23{
24    /// Returns the next object from the collection being enumerated.
25    fn m_next_object(&self) -> ObjectType {
26        unsafe { ObjectType::from_id(msg_send![self.m_self(), nextObject]) }
27    }
28
29    /// The array of unenumerated objects.
30    fn m_all_objects(&self) -> NSArray<ObjectType> {
31        unsafe { NSArray::from_id(msg_send![self.m_self(), allObjects]) }
32    }
33}
34
35impl<ObjectType> INSEnumerator<ObjectType> for NSEnumerator<ObjectType> where
36    ObjectType: PNSObject + FromId
37{
38}