objc2_core_foundation/generated/CFError.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
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cferrordomain?language=objc)
11// NS_TYPED_EXTENSIBLE_ENUM
12#[cfg(feature = "CFBase")]
13pub type CFErrorDomain = CFString;
14
15/// This is the type of a reference to CFErrors. CFErrorRef is toll-free bridged with NSError.
16///
17/// See also [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cferror?language=objc)
18#[repr(C)]
19pub struct CFError {
20 inner: [u8; 0],
21 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
22}
23
24cf_type!(
25 #[encoding_name = "__CFError"]
26 unsafe impl CFError {}
27);
28
29#[cfg(feature = "CFBase")]
30unsafe impl ConcreteType for CFError {
31 /// Returns the type identifier of all CFError instances.
32 #[doc(alias = "CFErrorGetTypeID")]
33 #[inline]
34 fn type_id() -> CFTypeID {
35 extern "C-unwind" {
36 fn CFErrorGetTypeID() -> CFTypeID;
37 }
38 unsafe { CFErrorGetTypeID() }
39 }
40}
41
42extern "C" {
43 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordomainposix?language=objc)
44 #[cfg(feature = "CFBase")]
45 pub static kCFErrorDomainPOSIX: Option<&'static CFErrorDomain>;
46}
47
48extern "C" {
49 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordomainosstatus?language=objc)
50 #[cfg(feature = "CFBase")]
51 pub static kCFErrorDomainOSStatus: Option<&'static CFErrorDomain>;
52}
53
54extern "C" {
55 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordomainmach?language=objc)
56 #[cfg(feature = "CFBase")]
57 pub static kCFErrorDomainMach: Option<&'static CFErrorDomain>;
58}
59
60extern "C" {
61 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordomaincocoa?language=objc)
62 #[cfg(feature = "CFBase")]
63 pub static kCFErrorDomainCocoa: Option<&'static CFErrorDomain>;
64}
65
66extern "C" {
67 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorlocalizeddescriptionkey?language=objc)
68 #[cfg(feature = "CFBase")]
69 pub static kCFErrorLocalizedDescriptionKey: Option<&'static CFString>;
70}
71
72extern "C" {
73 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorlocalizedfailurekey?language=objc)
74 #[cfg(feature = "CFBase")]
75 pub static kCFErrorLocalizedFailureKey: Option<&'static CFString>;
76}
77
78extern "C" {
79 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorlocalizedfailurereasonkey?language=objc)
80 #[cfg(feature = "CFBase")]
81 pub static kCFErrorLocalizedFailureReasonKey: Option<&'static CFString>;
82}
83
84extern "C" {
85 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorlocalizedrecoverysuggestionkey?language=objc)
86 #[cfg(feature = "CFBase")]
87 pub static kCFErrorLocalizedRecoverySuggestionKey: Option<&'static CFString>;
88}
89
90extern "C" {
91 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrordescriptionkey?language=objc)
92 #[cfg(feature = "CFBase")]
93 pub static kCFErrorDescriptionKey: Option<&'static CFString>;
94}
95
96extern "C" {
97 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorunderlyingerrorkey?language=objc)
98 #[cfg(feature = "CFBase")]
99 pub static kCFErrorUnderlyingErrorKey: Option<&'static CFString>;
100}
101
102extern "C" {
103 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorurlkey?language=objc)
104 #[cfg(feature = "CFBase")]
105 pub static kCFErrorURLKey: Option<&'static CFString>;
106}
107
108extern "C" {
109 /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcferrorfilepathkey?language=objc)
110 #[cfg(feature = "CFBase")]
111 pub static kCFErrorFilePathKey: Option<&'static CFString>;
112}
113
114/// Creates a new CFError.
115///
116/// Parameter `allocator`: The CFAllocator which should be used to allocate memory for the error. This parameter may be NULL in which case the
117/// current default CFAllocator is used. If this reference is not a valid CFAllocator, the behavior is undefined.
118///
119/// Parameter `domain`: A CFString identifying the error domain. If this reference is NULL or is otherwise not a valid CFString, the behavior is undefined.
120///
121/// Parameter `code`: A CFIndex identifying the error code. The code is interpreted within the context of the error domain.
122///
123/// Parameter `userInfo`: A CFDictionary created with kCFCopyStringDictionaryKeyCallBacks and kCFTypeDictionaryValueCallBacks. It will be copied with CFDictionaryCreateCopy().
124/// If no userInfo dictionary is desired, NULL may be passed in as a convenience, in which case an empty userInfo dictionary will be assigned.
125///
126/// Returns: A reference to the new CFError.
127#[cfg(all(feature = "CFBase", feature = "CFDictionary"))]
128#[inline]
129pub unsafe extern "C-unwind" fn CFErrorCreate(
130 allocator: Option<&CFAllocator>,
131 domain: Option<&CFErrorDomain>,
132 code: CFIndex,
133 user_info: Option<&CFDictionary>,
134) -> Option<CFRetained<CFError>> {
135 extern "C-unwind" {
136 fn CFErrorCreate(
137 allocator: Option<&CFAllocator>,
138 domain: Option<&CFErrorDomain>,
139 code: CFIndex,
140 user_info: Option<&CFDictionary>,
141 ) -> Option<NonNull<CFError>>;
142 }
143 let ret = unsafe { CFErrorCreate(allocator, domain, code, user_info) };
144 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
145}
146
147/// Creates a new CFError without having to create an intermediate userInfo dictionary.
148///
149/// Parameter `allocator`: The CFAllocator which should be used to allocate memory for the error. This parameter may be NULL in which case the
150/// current default CFAllocator is used. If this reference is not a valid CFAllocator, the behavior is undefined.
151///
152/// Parameter `domain`: A CFString identifying the error domain. If this reference is NULL or is otherwise not a valid CFString, the behavior is undefined.
153///
154/// Parameter `code`: A CFIndex identifying the error code. The code is interpreted within the context of the error domain.
155///
156/// Parameter `userInfoKeys`: An array of numUserInfoValues CFStrings used as keys in creating the userInfo dictionary. NULL is valid only if numUserInfoValues is 0.
157///
158/// Parameter `userInfoValues`: An array of numUserInfoValues CF types used as values in creating the userInfo dictionary. NULL is valid only if numUserInfoValues is 0.
159///
160/// Parameter `numUserInfoValues`: CFIndex representing the number of keys and values in the userInfoKeys and userInfoValues arrays.
161///
162/// Returns: A reference to the new CFError. numUserInfoValues CF types are gathered from each of userInfoKeys and userInfoValues to create the userInfo dictionary.
163#[cfg(feature = "CFBase")]
164#[inline]
165pub unsafe extern "C-unwind" fn CFErrorCreateWithUserInfoKeysAndValues(
166 allocator: Option<&CFAllocator>,
167 domain: Option<&CFErrorDomain>,
168 code: CFIndex,
169 user_info_keys: *const *const c_void,
170 user_info_values: *const *const c_void,
171 num_user_info_values: CFIndex,
172) -> Option<CFRetained<CFError>> {
173 extern "C-unwind" {
174 fn CFErrorCreateWithUserInfoKeysAndValues(
175 allocator: Option<&CFAllocator>,
176 domain: Option<&CFErrorDomain>,
177 code: CFIndex,
178 user_info_keys: *const *const c_void,
179 user_info_values: *const *const c_void,
180 num_user_info_values: CFIndex,
181 ) -> Option<NonNull<CFError>>;
182 }
183 let ret = unsafe {
184 CFErrorCreateWithUserInfoKeysAndValues(
185 allocator,
186 domain,
187 code,
188 user_info_keys,
189 user_info_values,
190 num_user_info_values,
191 )
192 };
193 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
194}
195
196/// Returns the error domain the CFError was created with.
197///
198/// Parameter `err`: The CFError whose error domain is to be returned. If this reference is not a valid CFError, the behavior is undefined.
199///
200/// Returns: The error domain of the CFError. Since this is a "Get" function, the caller shouldn't CFRelease the return value.
201#[cfg(feature = "CFBase")]
202#[inline]
203pub unsafe extern "C-unwind" fn CFErrorGetDomain(
204 err: &CFError,
205) -> Option<CFRetained<CFErrorDomain>> {
206 extern "C-unwind" {
207 fn CFErrorGetDomain(err: &CFError) -> Option<NonNull<CFErrorDomain>>;
208 }
209 let ret = unsafe { CFErrorGetDomain(err) };
210 ret.map(|ret| unsafe { CFRetained::retain(ret) })
211}
212
213extern "C-unwind" {
214 /// Returns the error code the CFError was created with.
215 ///
216 /// Parameter `err`: The CFError whose error code is to be returned. If this reference is not a valid CFError, the behavior is undefined.
217 ///
218 /// Returns: The error code of the CFError (not an error return for the current call).
219 #[cfg(feature = "CFBase")]
220 pub fn CFErrorGetCode(err: &CFError) -> CFIndex;
221}
222
223/// Returns CFError userInfo dictionary.
224///
225/// Returns a dictionary containing the same keys and values as in the userInfo dictionary the CFError was created with. Returns an empty dictionary if NULL was supplied to CFErrorCreate().
226///
227/// Parameter `err`: The CFError whose error user info is to be returned. If this reference is not a valid CFError, the behavior is undefined.
228///
229/// Returns: The user info of the CFError.
230#[cfg(feature = "CFDictionary")]
231#[inline]
232pub unsafe extern "C-unwind" fn CFErrorCopyUserInfo(
233 err: &CFError,
234) -> Option<CFRetained<CFDictionary>> {
235 extern "C-unwind" {
236 fn CFErrorCopyUserInfo(err: &CFError) -> Option<NonNull<CFDictionary>>;
237 }
238 let ret = unsafe { CFErrorCopyUserInfo(err) };
239 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
240}
241
242/// Returns a human-presentable description for the error. CFError creators should strive to make sure the return value is human-presentable and localized by providing a value for kCFErrorLocalizedDescriptionKey at the time of CFError creation.
243///
244/// This is a complete sentence or two which says what failed and why it failed. Please refer to header comments for -[NSError localizedDescription] for details on the steps used to compute this; but roughly:
245/// - Use value of kCFErrorLocalizedDescriptionKey as-is if provided.
246/// - Use value of kCFErrorLocalizedFailureKey if provided, optionally followed by kCFErrorLocalizedFailureReasonKey if available.
247/// - Use value of kCFErrorLocalizedFailureReasonKey, combining with a generic failure message such as: "Operation code not be completed. " + kCFErrorLocalizedFailureReasonKey.
248/// - If all of the above fail, generate a semi-user presentable string from kCFErrorDescriptionKey, the domain, and code. Something like: "Operation could not be completed. Error domain/code occurred. " or "Operation could not be completed. " + kCFErrorDescriptionKey + " (Error domain/code)"
249/// Toll-free bridged NSError instances might provide additional behaviors for manufacturing a description string. Do not count on the exact contents or format of the returned string, it might change.
250///
251/// Parameter `err`: The CFError whose description is to be returned. If this reference is not a valid CFError, the behavior is undefined.
252///
253/// Returns: A CFString with human-presentable description of the CFError. Never NULL.
254#[cfg(feature = "CFBase")]
255#[inline]
256pub unsafe extern "C-unwind" fn CFErrorCopyDescription(
257 err: &CFError,
258) -> Option<CFRetained<CFString>> {
259 extern "C-unwind" {
260 fn CFErrorCopyDescription(err: &CFError) -> Option<NonNull<CFString>>;
261 }
262 let ret = unsafe { CFErrorCopyDescription(err) };
263 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
264}
265
266/// Returns a human-presentable failure reason for the error. May return NULL. CFError creators should strive to make sure the return value is human-presentable and localized by providing a value for kCFErrorLocalizedFailureReasonKey at the time of CFError creation.
267///
268/// This is a complete sentence which describes why the operation failed. In many cases this will be just the "because" part of the description (but as a complete sentence, which makes localization easier). By default this looks for kCFErrorLocalizedFailureReasonKey in the user info. Toll-free bridged NSError instances might provide additional behaviors for manufacturing this value. If no user-presentable string is available, returns NULL.
269/// Example Description: "Could not save file 'Letter' in folder 'Documents' because the volume 'MyDisk' doesn't have enough space."
270/// Corresponding FailureReason: "The volume 'MyDisk' doesn't have enough space."
271///
272/// Parameter `err`: The CFError whose failure reason is to be returned. If this reference is not a valid CFError, the behavior is undefined.
273///
274/// Returns: A CFString with the localized, end-user presentable failure reason of the CFError, or NULL.
275#[cfg(feature = "CFBase")]
276#[inline]
277pub unsafe extern "C-unwind" fn CFErrorCopyFailureReason(
278 err: &CFError,
279) -> Option<CFRetained<CFString>> {
280 extern "C-unwind" {
281 fn CFErrorCopyFailureReason(err: &CFError) -> Option<NonNull<CFString>>;
282 }
283 let ret = unsafe { CFErrorCopyFailureReason(err) };
284 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
285}
286
287/// Returns a human presentable recovery suggestion for the error. May return NULL. CFError creators should strive to make sure the return value is human-presentable and localized by providing a value for kCFErrorLocalizedRecoverySuggestionKey at the time of CFError creation.
288///
289/// This is the string that can be displayed as the "informative" (aka "secondary") message on an alert panel. By default this looks for kCFErrorLocalizedRecoverySuggestionKey in the user info. Toll-free bridged NSError instances might provide additional behaviors for manufacturing this value. If no user-presentable string is available, returns NULL.
290/// Example Description: "Could not save file 'Letter' in folder 'Documents' because the volume 'MyDisk' doesn't have enough space."
291/// Corresponding RecoverySuggestion: "Remove some files from the volume and try again."
292///
293/// Parameter `err`: The CFError whose recovery suggestion is to be returned. If this reference is not a valid CFError, the behavior is undefined.
294///
295/// Returns: A CFString with the localized, end-user presentable recovery suggestion of the CFError, or NULL.
296#[cfg(feature = "CFBase")]
297#[inline]
298pub unsafe extern "C-unwind" fn CFErrorCopyRecoverySuggestion(
299 err: &CFError,
300) -> Option<CFRetained<CFString>> {
301 extern "C-unwind" {
302 fn CFErrorCopyRecoverySuggestion(err: &CFError) -> Option<NonNull<CFString>>;
303 }
304 let ret = unsafe { CFErrorCopyRecoverySuggestion(err) };
305 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
306}