objc2_core_foundation/generated/
CFBase.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatortypeid?language=objc)
13pub type CFAllocatorTypeID = c_ulonglong;
14
15extern "C" {
16    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfcorefoundationversionnumber?language=objc)
17    pub static kCFCoreFoundationVersionNumber: c_double;
18}
19
20/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfstring?language=objc)
21#[repr(C)]
22pub struct CFString {
23    inner: [u8; 0],
24    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
25}
26
27cf_type!(
28    #[encoding_name = "__CFString"]
29    unsafe impl CFString {}
30);
31
32/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfmutablestring?language=objc)
33#[repr(C)]
34pub struct CFMutableString {
35    inner: [u8; 0],
36    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
37}
38
39cf_type!(
40    #[encoding_name = "__CFString"]
41    unsafe impl CFMutableString: CFString {}
42);
43
44/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfpropertylist?language=objc)
45pub type CFPropertyList = CFType;
46
47/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfcomparisonresult?language=objc)
48// NS_ENUM
49#[repr(transparent)]
50#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
51pub struct CFComparisonResult(pub CFIndex);
52impl CFComparisonResult {
53    #[doc(alias = "kCFCompareLessThan")]
54    pub const CompareLessThan: Self = Self(-1);
55    #[doc(alias = "kCFCompareEqualTo")]
56    pub const CompareEqualTo: Self = Self(0);
57    #[doc(alias = "kCFCompareGreaterThan")]
58    pub const CompareGreaterThan: Self = Self(1);
59}
60
61#[cfg(feature = "objc2")]
62unsafe impl Encode for CFComparisonResult {
63    const ENCODING: Encoding = CFIndex::ENCODING;
64}
65
66#[cfg(feature = "objc2")]
67unsafe impl RefEncode for CFComparisonResult {
68    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
69}
70
71/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfcomparatorfunction?language=objc)
72pub type CFComparatorFunction = Option<
73    unsafe extern "C-unwind" fn(*const c_void, *const c_void, *mut c_void) -> CFComparisonResult,
74>;
75
76/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnotfound?language=objc)
77pub static kCFNotFound: CFIndex = -1;
78
79/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfrange?language=objc)
80#[repr(C)]
81#[derive(Clone, Copy, Debug, PartialEq)]
82pub struct CFRange {
83    pub location: CFIndex,
84    pub length: CFIndex,
85}
86
87#[cfg(feature = "objc2")]
88unsafe impl Encode for CFRange {
89    const ENCODING: Encoding = Encoding::Struct("?", &[<CFIndex>::ENCODING, <CFIndex>::ENCODING]);
90}
91
92#[cfg(feature = "objc2")]
93unsafe impl RefEncode for CFRange {
94    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
95}
96
97// TODO: pub fn CFRangeMake(loc: CFIndex,len: CFIndex,) -> CFRange;
98
99/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfnull?language=objc)
100#[repr(C)]
101pub struct CFNull {
102    inner: [u8; 0],
103    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
104}
105
106cf_type!(
107    #[encoding_name = "__CFNull"]
108    unsafe impl CFNull {}
109);
110
111unsafe impl ConcreteType for CFNull {
112    #[doc(alias = "CFNullGetTypeID")]
113    #[inline]
114    fn type_id() -> CFTypeID {
115        extern "C-unwind" {
116            fn CFNullGetTypeID() -> CFTypeID;
117        }
118        unsafe { CFNullGetTypeID() }
119    }
120}
121
122extern "C" {
123    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfnull?language=objc)
124    pub static kCFNull: Option<&'static CFNull>;
125}
126
127/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocator?language=objc)
128#[repr(C)]
129pub struct CFAllocator {
130    inner: [u8; 0],
131    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
132}
133
134cf_type!(
135    #[encoding_name = "__CFAllocator"]
136    unsafe impl CFAllocator {}
137);
138
139extern "C" {
140    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatordefault?language=objc)
141    pub static kCFAllocatorDefault: Option<&'static CFAllocator>;
142}
143
144extern "C" {
145    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatorsystemdefault?language=objc)
146    pub static kCFAllocatorSystemDefault: Option<&'static CFAllocator>;
147}
148
149extern "C" {
150    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatormalloc?language=objc)
151    pub static kCFAllocatorMalloc: Option<&'static CFAllocator>;
152}
153
154extern "C" {
155    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatormalloczone?language=objc)
156    pub static kCFAllocatorMallocZone: Option<&'static CFAllocator>;
157}
158
159extern "C" {
160    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatornull?language=objc)
161    pub static kCFAllocatorNull: Option<&'static CFAllocator>;
162}
163
164extern "C" {
165    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfallocatorusecontext?language=objc)
166    pub static kCFAllocatorUseContext: Option<&'static CFAllocator>;
167}
168
169/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorretaincallback?language=objc)
170pub type CFAllocatorRetainCallBack =
171    Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>;
172
173/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorreleasecallback?language=objc)
174pub type CFAllocatorReleaseCallBack = Option<unsafe extern "C-unwind" fn(*const c_void)>;
175
176/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorcopydescriptioncallback?language=objc)
177pub type CFAllocatorCopyDescriptionCallBack =
178    Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>;
179
180/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorallocatecallback?language=objc)
181pub type CFAllocatorAllocateCallBack =
182    Option<unsafe extern "C-unwind" fn(CFIndex, CFOptionFlags, *mut c_void) -> *mut c_void>;
183
184/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorreallocatecallback?language=objc)
185pub type CFAllocatorReallocateCallBack = Option<
186    unsafe extern "C-unwind" fn(*mut c_void, CFIndex, CFOptionFlags, *mut c_void) -> *mut c_void,
187>;
188
189/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatordeallocatecallback?language=objc)
190pub type CFAllocatorDeallocateCallBack =
191    Option<unsafe extern "C-unwind" fn(*mut c_void, *mut c_void)>;
192
193/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorpreferredsizecallback?language=objc)
194pub type CFAllocatorPreferredSizeCallBack =
195    Option<unsafe extern "C-unwind" fn(CFIndex, CFOptionFlags, *mut c_void) -> CFIndex>;
196
197/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfallocatorcontext?language=objc)
198#[repr(C)]
199#[derive(Clone, Copy, Debug, PartialEq)]
200pub struct CFAllocatorContext {
201    pub version: CFIndex,
202    pub info: *mut c_void,
203    pub retain: CFAllocatorRetainCallBack,
204    pub release: CFAllocatorReleaseCallBack,
205    pub copyDescription: CFAllocatorCopyDescriptionCallBack,
206    pub allocate: CFAllocatorAllocateCallBack,
207    pub reallocate: CFAllocatorReallocateCallBack,
208    pub deallocate: CFAllocatorDeallocateCallBack,
209    pub preferredSize: CFAllocatorPreferredSizeCallBack,
210}
211
212#[cfg(feature = "objc2")]
213unsafe impl Encode for CFAllocatorContext {
214    const ENCODING: Encoding = Encoding::Struct(
215        "?",
216        &[
217            <CFIndex>::ENCODING,
218            <*mut c_void>::ENCODING,
219            <CFAllocatorRetainCallBack>::ENCODING,
220            <CFAllocatorReleaseCallBack>::ENCODING,
221            <CFAllocatorCopyDescriptionCallBack>::ENCODING,
222            <CFAllocatorAllocateCallBack>::ENCODING,
223            <CFAllocatorReallocateCallBack>::ENCODING,
224            <CFAllocatorDeallocateCallBack>::ENCODING,
225            <CFAllocatorPreferredSizeCallBack>::ENCODING,
226        ],
227    );
228}
229
230#[cfg(feature = "objc2")]
231unsafe impl RefEncode for CFAllocatorContext {
232    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
233}
234
235unsafe impl ConcreteType for CFAllocator {
236    #[doc(alias = "CFAllocatorGetTypeID")]
237    #[inline]
238    fn type_id() -> CFTypeID {
239        extern "C-unwind" {
240            fn CFAllocatorGetTypeID() -> CFTypeID;
241        }
242        unsafe { CFAllocatorGetTypeID() }
243    }
244}
245
246extern "C-unwind" {
247    pub fn CFAllocatorSetDefault(allocator: Option<&CFAllocator>);
248}
249
250#[inline]
251pub unsafe extern "C-unwind" fn CFAllocatorGetDefault() -> Option<CFRetained<CFAllocator>> {
252    extern "C-unwind" {
253        fn CFAllocatorGetDefault() -> Option<NonNull<CFAllocator>>;
254    }
255    let ret = unsafe { CFAllocatorGetDefault() };
256    ret.map(|ret| unsafe { CFRetained::retain(ret) })
257}
258
259#[inline]
260pub unsafe extern "C-unwind" fn CFAllocatorCreate(
261    allocator: Option<&CFAllocator>,
262    context: *mut CFAllocatorContext,
263) -> Option<CFRetained<CFAllocator>> {
264    extern "C-unwind" {
265        fn CFAllocatorCreate(
266            allocator: Option<&CFAllocator>,
267            context: *mut CFAllocatorContext,
268        ) -> Option<NonNull<CFAllocator>>;
269    }
270    let ret = unsafe { CFAllocatorCreate(allocator, context) };
271    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
272}
273
274extern "C-unwind" {
275    pub fn CFAllocatorAllocateTyped(
276        allocator: Option<&CFAllocator>,
277        size: CFIndex,
278        descriptor: CFAllocatorTypeID,
279        hint: CFOptionFlags,
280    ) -> *mut c_void;
281}
282
283extern "C-unwind" {
284    pub fn CFAllocatorReallocateTyped(
285        allocator: Option<&CFAllocator>,
286        ptr: *mut c_void,
287        newsize: CFIndex,
288        descriptor: CFAllocatorTypeID,
289        hint: CFOptionFlags,
290    ) -> *mut c_void;
291}
292
293extern "C-unwind" {
294    pub fn CFAllocatorAllocateBytes(
295        allocator: Option<&CFAllocator>,
296        size: CFIndex,
297        hint: CFOptionFlags,
298    ) -> *mut c_void;
299}
300
301extern "C-unwind" {
302    pub fn CFAllocatorReallocateBytes(
303        allocator: Option<&CFAllocator>,
304        ptr: *mut c_void,
305        newsize: CFIndex,
306        hint: CFOptionFlags,
307    ) -> *mut c_void;
308}
309
310extern "C-unwind" {
311    pub fn CFAllocatorAllocate(
312        allocator: Option<&CFAllocator>,
313        size: CFIndex,
314        hint: CFOptionFlags,
315    ) -> *mut c_void;
316}
317
318extern "C-unwind" {
319    pub fn CFAllocatorReallocate(
320        allocator: Option<&CFAllocator>,
321        ptr: *mut c_void,
322        newsize: CFIndex,
323        hint: CFOptionFlags,
324    ) -> *mut c_void;
325}
326
327extern "C-unwind" {
328    pub fn CFAllocatorDeallocate(allocator: Option<&CFAllocator>, ptr: *mut c_void);
329}
330
331extern "C-unwind" {
332    pub fn CFAllocatorGetPreferredSizeForSize(
333        allocator: Option<&CFAllocator>,
334        size: CFIndex,
335        hint: CFOptionFlags,
336    ) -> CFIndex;
337}
338
339extern "C-unwind" {
340    pub fn CFAllocatorGetContext(allocator: Option<&CFAllocator>, context: *mut CFAllocatorContext);
341}
342
343#[inline]
344pub extern "C-unwind" fn CFGetTypeID(cf: Option<&CFType>) -> CFTypeID {
345    extern "C-unwind" {
346        fn CFGetTypeID(cf: Option<&CFType>) -> CFTypeID;
347    }
348    unsafe { CFGetTypeID(cf) }
349}
350
351#[inline]
352pub extern "C-unwind" fn CFCopyTypeIDDescription(
353    type_id: CFTypeID,
354) -> Option<CFRetained<CFString>> {
355    extern "C-unwind" {
356        fn CFCopyTypeIDDescription(type_id: CFTypeID) -> Option<NonNull<CFString>>;
357    }
358    let ret = unsafe { CFCopyTypeIDDescription(type_id) };
359    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
360}
361
362#[inline]
363pub extern "C-unwind" fn CFGetRetainCount(cf: Option<&CFType>) -> CFIndex {
364    extern "C-unwind" {
365        fn CFGetRetainCount(cf: Option<&CFType>) -> CFIndex;
366    }
367    unsafe { CFGetRetainCount(cf) }
368}
369
370#[inline]
371pub extern "C-unwind" fn CFEqual(cf1: Option<&CFType>, cf2: Option<&CFType>) -> bool {
372    extern "C-unwind" {
373        fn CFEqual(cf1: Option<&CFType>, cf2: Option<&CFType>) -> Boolean;
374    }
375    let ret = unsafe { CFEqual(cf1, cf2) };
376    ret != 0
377}
378
379#[inline]
380pub extern "C-unwind" fn CFHash(cf: Option<&CFType>) -> CFHashCode {
381    extern "C-unwind" {
382        fn CFHash(cf: Option<&CFType>) -> CFHashCode;
383    }
384    unsafe { CFHash(cf) }
385}
386
387#[inline]
388pub extern "C-unwind" fn CFCopyDescription(cf: Option<&CFType>) -> Option<CFRetained<CFString>> {
389    extern "C-unwind" {
390        fn CFCopyDescription(cf: Option<&CFType>) -> Option<NonNull<CFString>>;
391    }
392    let ret = unsafe { CFCopyDescription(cf) };
393    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
394}
395
396#[inline]
397pub unsafe extern "C-unwind" fn CFGetAllocator(
398    cf: Option<&CFType>,
399) -> Option<CFRetained<CFAllocator>> {
400    extern "C-unwind" {
401        fn CFGetAllocator(cf: Option<&CFType>) -> Option<NonNull<CFAllocator>>;
402    }
403    let ret = unsafe { CFGetAllocator(cf) };
404    ret.map(|ret| unsafe { CFRetained::retain(ret) })
405}