rust_macios/contacts/
cn_fetch_result.rs

1use std::marker::PhantomData;
2
3use objc::{msg_send, sel, sel_impl};
4
5use crate::{
6    foundation::NSData,
7    object,
8    objective_c_runtime::traits::{FromId, PNSObject},
9};
10
11object! {
12    ///
13    unsafe pub struct CNFetchResult<ValueType> {
14        marker: PhantomData<ValueType>,
15    }
16}
17
18///
19pub trait ICNFetchResult<ValueType>: PNSObject
20where
21    ValueType: PNSObject + FromId,
22{
23    ///
24    fn p_current_history_token(&self) -> NSData {
25        unsafe { NSData::from_id(msg_send![self.m_self(), currentHistoryToken]) }
26    }
27
28    ///
29    fn p_value(&self) -> ValueType {
30        unsafe { ValueType::from_id(msg_send![self.m_self(), value]) }
31    }
32}
33
34impl<ValueType> ICNFetchResult<ValueType> for CNFetchResult<ValueType> where
35    ValueType: PNSObject + FromId
36{
37}
38
39impl<ValueType> CNFetchResult<ValueType>
40where
41    ValueType: PNSObject + FromId,
42{
43    ///
44    pub fn current_history_token(&self) -> NSData {
45        self.p_current_history_token()
46    }
47
48    ///
49    pub fn value(&self) -> ValueType {
50        self.p_value()
51    }
52}