Skip to main content

objc2_core_foundation/generated/
CFURLEnumerator.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/cfurlenumerator?language=objc)
13#[doc(alias = "CFURLEnumeratorRef")]
14#[repr(C)]
15pub struct CFURLEnumerator {
16    inner: [u8; 0],
17    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
18}
19
20cf_type!(
21    unsafe impl CFURLEnumerator {}
22);
23#[cfg(feature = "objc2")]
24cf_objc2_type!(
25    unsafe impl RefEncode<"__CFURLEnumerator"> for CFURLEnumerator {}
26);
27
28unsafe impl ConcreteType for CFURLEnumerator {
29    #[doc(alias = "CFURLEnumeratorGetTypeID")]
30    #[inline]
31    fn type_id() -> CFTypeID {
32        extern "C-unwind" {
33            fn CFURLEnumeratorGetTypeID() -> CFTypeID;
34        }
35        unsafe { CFURLEnumeratorGetTypeID() }
36    }
37}
38
39/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfurlenumeratoroptions?language=objc)
40// NS_OPTIONS
41#[repr(transparent)]
42#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
43pub struct CFURLEnumeratorOptions(pub CFOptionFlags);
44bitflags::bitflags! {
45    impl CFURLEnumeratorOptions: CFOptionFlags {
46        #[doc(alias = "kCFURLEnumeratorDefaultBehavior")]
47        const DefaultBehavior = 0;
48        #[doc(alias = "kCFURLEnumeratorDescendRecursively")]
49        const DescendRecursively = 1<<0;
50        #[doc(alias = "kCFURLEnumeratorSkipInvisibles")]
51        const SkipInvisibles = 1<<1;
52        #[doc(alias = "kCFURLEnumeratorGenerateFileReferenceURLs")]
53        const GenerateFileReferenceURLs = 1<<2;
54        #[doc(alias = "kCFURLEnumeratorSkipPackageContents")]
55        const SkipPackageContents = 1<<3;
56        #[doc(alias = "kCFURLEnumeratorIncludeDirectoriesPreOrder")]
57        const IncludeDirectoriesPreOrder = 1<<4;
58        #[doc(alias = "kCFURLEnumeratorIncludeDirectoriesPostOrder")]
59        const IncludeDirectoriesPostOrder = 1<<5;
60        #[doc(alias = "kCFURLEnumeratorGenerateRelativePathURLs")]
61        const GenerateRelativePathURLs = 1<<6;
62    }
63}
64
65#[cfg(feature = "objc2")]
66unsafe impl Encode for CFURLEnumeratorOptions {
67    const ENCODING: Encoding = CFOptionFlags::ENCODING;
68}
69
70#[cfg(feature = "objc2")]
71unsafe impl RefEncode for CFURLEnumeratorOptions {
72    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
73}
74
75impl CFURLEnumerator {
76    /// # Safety
77    ///
78    /// - `alloc` might not allow `None`.
79    /// - `directory_url` might not allow `None`.
80    /// - `property_keys` generic must be of the correct type.
81    /// - `property_keys` might not allow `None`.
82    #[doc(alias = "CFURLEnumeratorCreateForDirectoryURL")]
83    #[cfg(all(feature = "CFArray", feature = "CFURL"))]
84    #[inline]
85    pub unsafe fn new_for_directory_url(
86        alloc: Option<&CFAllocator>,
87        directory_url: Option<&CFURL>,
88        option: CFURLEnumeratorOptions,
89        property_keys: Option<&CFArray>,
90    ) -> Option<CFRetained<CFURLEnumerator>> {
91        extern "C-unwind" {
92            fn CFURLEnumeratorCreateForDirectoryURL(
93                alloc: Option<&CFAllocator>,
94                directory_url: Option<&CFURL>,
95                option: CFURLEnumeratorOptions,
96                property_keys: Option<&CFArray>,
97            ) -> Option<NonNull<CFURLEnumerator>>;
98        }
99        let ret = unsafe {
100            CFURLEnumeratorCreateForDirectoryURL(alloc, directory_url, option, property_keys)
101        };
102        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
103    }
104
105    /// # Safety
106    ///
107    /// - `alloc` might not allow `None`.
108    /// - `property_keys` generic must be of the correct type.
109    /// - `property_keys` might not allow `None`.
110    #[doc(alias = "CFURLEnumeratorCreateForMountedVolumes")]
111    #[cfg(feature = "CFArray")]
112    #[inline]
113    pub unsafe fn new_for_mounted_volumes(
114        alloc: Option<&CFAllocator>,
115        option: CFURLEnumeratorOptions,
116        property_keys: Option<&CFArray>,
117    ) -> Option<CFRetained<CFURLEnumerator>> {
118        extern "C-unwind" {
119            fn CFURLEnumeratorCreateForMountedVolumes(
120                alloc: Option<&CFAllocator>,
121                option: CFURLEnumeratorOptions,
122                property_keys: Option<&CFArray>,
123            ) -> Option<NonNull<CFURLEnumerator>>;
124        }
125        let ret = unsafe { CFURLEnumeratorCreateForMountedVolumes(alloc, option, property_keys) };
126        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
127    }
128}
129
130/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfurlenumeratorresult?language=objc)
131// NS_ENUM
132#[repr(transparent)]
133#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
134pub struct CFURLEnumeratorResult(pub CFIndex);
135impl CFURLEnumeratorResult {
136    #[doc(alias = "kCFURLEnumeratorSuccess")]
137    pub const Success: Self = Self(1);
138    #[doc(alias = "kCFURLEnumeratorEnd")]
139    pub const End: Self = Self(2);
140    #[doc(alias = "kCFURLEnumeratorError")]
141    pub const Error: Self = Self(3);
142    #[doc(alias = "kCFURLEnumeratorDirectoryPostOrderSuccess")]
143    pub const DirectoryPostOrderSuccess: Self = Self(4);
144}
145
146#[cfg(feature = "objc2")]
147unsafe impl Encode for CFURLEnumeratorResult {
148    const ENCODING: Encoding = CFIndex::ENCODING;
149}
150
151#[cfg(feature = "objc2")]
152unsafe impl RefEncode for CFURLEnumeratorResult {
153    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
154}
155
156impl CFURLEnumerator {
157    /// # Safety
158    ///
159    /// - `url` must be a valid pointer.
160    /// - `error` must be a valid pointer.
161    #[doc(alias = "CFURLEnumeratorGetNextURL")]
162    #[cfg(all(feature = "CFError", feature = "CFURL"))]
163    #[inline]
164    pub unsafe fn next_url(
165        &self,
166        url: *mut *const CFURL,
167        error: *mut *mut CFError,
168    ) -> CFURLEnumeratorResult {
169        extern "C-unwind" {
170            fn CFURLEnumeratorGetNextURL(
171                enumerator: &CFURLEnumerator,
172                url: *mut *const CFURL,
173                error: *mut *mut CFError,
174            ) -> CFURLEnumeratorResult;
175        }
176        unsafe { CFURLEnumeratorGetNextURL(self, url, error) }
177    }
178
179    #[doc(alias = "CFURLEnumeratorSkipDescendents")]
180    #[inline]
181    pub fn skip_descendents(&self) {
182        extern "C-unwind" {
183            fn CFURLEnumeratorSkipDescendents(enumerator: &CFURLEnumerator);
184        }
185        unsafe { CFURLEnumeratorSkipDescendents(self) }
186    }
187
188    #[doc(alias = "CFURLEnumeratorGetDescendentLevel")]
189    #[inline]
190    pub fn descendent_level(&self) -> CFIndex {
191        extern "C-unwind" {
192            fn CFURLEnumeratorGetDescendentLevel(enumerator: &CFURLEnumerator) -> CFIndex;
193        }
194        unsafe { CFURLEnumeratorGetDescendentLevel(self) }
195    }
196
197    #[doc(alias = "CFURLEnumeratorGetSourceDidChange")]
198    #[deprecated = "Use File System Events API instead"]
199    #[inline]
200    pub fn source_did_change(&self) -> bool {
201        extern "C-unwind" {
202            fn CFURLEnumeratorGetSourceDidChange(enumerator: &CFURLEnumerator) -> Boolean;
203        }
204        let ret = unsafe { CFURLEnumeratorGetSourceDidChange(self) };
205        ret != 0
206    }
207}
208
209#[cfg(all(feature = "CFArray", feature = "CFURL"))]
210#[deprecated = "renamed to `CFURLEnumerator::new_for_directory_url`"]
211#[inline]
212pub unsafe extern "C-unwind" fn CFURLEnumeratorCreateForDirectoryURL(
213    alloc: Option<&CFAllocator>,
214    directory_url: Option<&CFURL>,
215    option: CFURLEnumeratorOptions,
216    property_keys: Option<&CFArray>,
217) -> Option<CFRetained<CFURLEnumerator>> {
218    extern "C-unwind" {
219        fn CFURLEnumeratorCreateForDirectoryURL(
220            alloc: Option<&CFAllocator>,
221            directory_url: Option<&CFURL>,
222            option: CFURLEnumeratorOptions,
223            property_keys: Option<&CFArray>,
224        ) -> Option<NonNull<CFURLEnumerator>>;
225    }
226    let ret = unsafe {
227        CFURLEnumeratorCreateForDirectoryURL(alloc, directory_url, option, property_keys)
228    };
229    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
230}
231
232#[cfg(feature = "CFArray")]
233#[deprecated = "renamed to `CFURLEnumerator::new_for_mounted_volumes`"]
234#[inline]
235pub unsafe extern "C-unwind" fn CFURLEnumeratorCreateForMountedVolumes(
236    alloc: Option<&CFAllocator>,
237    option: CFURLEnumeratorOptions,
238    property_keys: Option<&CFArray>,
239) -> Option<CFRetained<CFURLEnumerator>> {
240    extern "C-unwind" {
241        fn CFURLEnumeratorCreateForMountedVolumes(
242            alloc: Option<&CFAllocator>,
243            option: CFURLEnumeratorOptions,
244            property_keys: Option<&CFArray>,
245        ) -> Option<NonNull<CFURLEnumerator>>;
246    }
247    let ret = unsafe { CFURLEnumeratorCreateForMountedVolumes(alloc, option, property_keys) };
248    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
249}
250
251extern "C-unwind" {
252    #[cfg(all(feature = "CFError", feature = "CFURL"))]
253    #[deprecated = "renamed to `CFURLEnumerator::next_url`"]
254    pub fn CFURLEnumeratorGetNextURL(
255        enumerator: &CFURLEnumerator,
256        url: *mut *const CFURL,
257        error: *mut *mut CFError,
258    ) -> CFURLEnumeratorResult;
259}
260
261#[deprecated = "renamed to `CFURLEnumerator::skip_descendents`"]
262#[inline]
263pub extern "C-unwind" fn CFURLEnumeratorSkipDescendents(enumerator: &CFURLEnumerator) {
264    extern "C-unwind" {
265        fn CFURLEnumeratorSkipDescendents(enumerator: &CFURLEnumerator);
266    }
267    unsafe { CFURLEnumeratorSkipDescendents(enumerator) }
268}
269
270#[deprecated = "renamed to `CFURLEnumerator::descendent_level`"]
271#[inline]
272pub extern "C-unwind" fn CFURLEnumeratorGetDescendentLevel(
273    enumerator: &CFURLEnumerator,
274) -> CFIndex {
275    extern "C-unwind" {
276        fn CFURLEnumeratorGetDescendentLevel(enumerator: &CFURLEnumerator) -> CFIndex;
277    }
278    unsafe { CFURLEnumeratorGetDescendentLevel(enumerator) }
279}
280
281#[deprecated = "renamed to `CFURLEnumerator::source_did_change`"]
282#[inline]
283pub extern "C-unwind" fn CFURLEnumeratorGetSourceDidChange(enumerator: &CFURLEnumerator) -> bool {
284    extern "C-unwind" {
285        fn CFURLEnumeratorGetSourceDidChange(enumerator: &CFURLEnumerator) -> Boolean;
286    }
287    let ret = unsafe { CFURLEnumeratorGetSourceDidChange(enumerator) };
288    ret != 0
289}