CFError

Struct CFError 

Source
#[repr(C)]
pub struct CFError { /* private fields */ }
Available on crate feature CFError only.
Expand description

This is the type of a reference to CFErrors. CFErrorRef is toll-free bridged with NSError.

See also Apple’s documentation

Implementations§

Source§

impl CFError

Source

pub unsafe fn new( allocator: Option<&CFAllocator>, domain: Option<&CFErrorDomain>, code: CFIndex, user_info: Option<&CFDictionary>, ) -> Option<CFRetained<CFError>>

Available on crate feature CFDictionary only.

Creates a new CFError.

Parameter allocator: The CFAllocator which should be used to allocate memory for the error. This parameter may be NULL in which case the current default CFAllocator is used. If this reference is not a valid CFAllocator, the behavior is undefined.

Parameter domain: A CFString identifying the error domain. If this reference is NULL or is otherwise not a valid CFString, the behavior is undefined.

Parameter code: A CFIndex identifying the error code. The code is interpreted within the context of the error domain.

Parameter userInfo: A CFDictionary created with kCFCopyStringDictionaryKeyCallBacks and kCFTypeDictionaryValueCallBacks. It will be copied with CFDictionaryCreateCopy(). If no userInfo dictionary is desired, NULL may be passed in as a convenience, in which case an empty userInfo dictionary will be assigned.

Returns: A reference to the new CFError.

Source

pub unsafe fn with_user_info_keys_and_values( allocator: Option<&CFAllocator>, domain: Option<&CFErrorDomain>, code: CFIndex, user_info_keys: *const *const c_void, user_info_values: *const *const c_void, num_user_info_values: CFIndex, ) -> Option<CFRetained<CFError>>

Creates a new CFError without having to create an intermediate userInfo dictionary.

Parameter allocator: The CFAllocator which should be used to allocate memory for the error. This parameter may be NULL in which case the current default CFAllocator is used. If this reference is not a valid CFAllocator, the behavior is undefined.

Parameter domain: A CFString identifying the error domain. If this reference is NULL or is otherwise not a valid CFString, the behavior is undefined.

Parameter code: A CFIndex identifying the error code. The code is interpreted within the context of the error domain.

Parameter userInfoKeys: An array of numUserInfoValues CFStrings used as keys in creating the userInfo dictionary. NULL is valid only if numUserInfoValues is 0.

Parameter userInfoValues: An array of numUserInfoValues CF types used as values in creating the userInfo dictionary. NULL is valid only if numUserInfoValues is 0.

Parameter numUserInfoValues: CFIndex representing the number of keys and values in the userInfoKeys and userInfoValues arrays.

Returns: A reference to the new CFError. numUserInfoValues CF types are gathered from each of userInfoKeys and userInfoValues to create the userInfo dictionary.

Source

pub fn domain(self: &CFError) -> Option<CFRetained<CFErrorDomain>>

Returns the error domain the CFError was created with.

Parameter err: The CFError whose error domain is to be returned. If this reference is not a valid CFError, the behavior is undefined.

Returns: The error domain of the CFError. Since this is a “Get” function, the caller shouldn’t CFRelease the return value.

Source

pub fn code(self: &CFError) -> CFIndex

Returns the error code the CFError was created with.

Parameter err: The CFError whose error code is to be returned. If this reference is not a valid CFError, the behavior is undefined.

Returns: The error code of the CFError (not an error return for the current call).

Source

pub fn user_info(self: &CFError) -> Option<CFRetained<CFDictionary>>

Available on crate feature CFDictionary only.

Returns CFError userInfo dictionary.

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().

Parameter err: The CFError whose error user info is to be returned. If this reference is not a valid CFError, the behavior is undefined.

Returns: The user info of the CFError.

Source

pub fn description(self: &CFError) -> Option<CFRetained<CFString>>

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.

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:

  • Use value of kCFErrorLocalizedDescriptionKey as-is if provided.
  • Use value of kCFErrorLocalizedFailureKey if provided, optionally followed by kCFErrorLocalizedFailureReasonKey if available.
  • Use value of kCFErrorLocalizedFailureReasonKey, combining with a generic failure message such as: “Operation code not be completed. “ + kCFErrorLocalizedFailureReasonKey.
  • 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)” 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.

Parameter err: The CFError whose description is to be returned. If this reference is not a valid CFError, the behavior is undefined.

Returns: A CFString with human-presentable description of the CFError. Never NULL.

Source

pub fn failure_reason(self: &CFError) -> Option<CFRetained<CFString>>

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.

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. Example Description: “Could not save file ‘Letter’ in folder ‘Documents’ because the volume ‘MyDisk’ doesn’t have enough space.” Corresponding FailureReason: “The volume ‘MyDisk’ doesn’t have enough space.”

Parameter err: The CFError whose failure reason is to be returned. If this reference is not a valid CFError, the behavior is undefined.

Returns: A CFString with the localized, end-user presentable failure reason of the CFError, or NULL.

Source

pub fn recovery_suggestion(self: &CFError) -> Option<CFRetained<CFString>>

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.

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. Example Description: “Could not save file ‘Letter’ in folder ‘Documents’ because the volume ‘MyDisk’ doesn’t have enough space.” Corresponding RecoverySuggestion: “Remove some files from the volume and try again.”

Parameter err: The CFError whose recovery suggestion is to be returned. If this reference is not a valid CFError, the behavior is undefined.

Returns: A CFString with the localized, end-user presentable recovery suggestion of the CFError, or NULL.

Methods from Deref<Target = CFType>§

Source

pub fn downcast_ref<T: ConcreteType>(&self) -> Option<&T>

Attempt to downcast the type to that of type T.

This is the reference-variant. Use CFRetained::downcast if you want to convert a retained type. See also ConcreteType for more details on which types support being converted to.

Source

pub fn retain_count(&self) -> usize

Get the reference count of the object.

This function may be useful for debugging. You normally do not use this function otherwise.

Beware that some things (like CFNumbers, small CFStrings etc.) may not have a normal retain count for optimization purposes, and can return usize::MAX in that case.

Trait Implementations§

Source§

impl AsRef<AnyObject> for CFError

Source§

fn as_ref(&self) -> &AnyObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<CFError> for CFError

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<CFType> for CFError

Source§

fn as_ref(&self) -> &CFType

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<AnyObject> for CFError

Source§

fn borrow(&self) -> &AnyObject

Immutably borrows from an owned value. Read more
Source§

impl Borrow<CFType> for CFError

Source§

fn borrow(&self) -> &CFType

Immutably borrows from an owned value. Read more
Source§

impl ConcreteType for CFError

Source§

fn type_id() -> CFTypeID

Returns the type identifier of all CFError instances.

Source§

impl Debug for CFError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for CFError

Source§

type Target = CFType

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Display for CFError

Available on crate feature CFString only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for CFError

Available on crate features CFString and std only.
1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl Hash for CFError

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Message for CFError

Source§

fn retain(&self) -> Retained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
Source§

impl PartialEq for CFError

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RefEncode for CFError

Source§

const ENCODING_REF: Encoding

The Objective-C type-encoding for a reference of this type. Read more
Source§

impl Type for CFError

Source§

fn retain(&self) -> CFRetained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
Source§

fn as_concrete_TypeRef(&self) -> &Self

👎Deprecated: this is redundant
Helper for easier transition from the core-foundation crate.
Source§

unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self>
where Self: Sized,

👎Deprecated: use CFRetained::retain
Helper for easier transition from the core-foundation crate. Read more
Source§

fn as_CFTypeRef(&self) -> &CFType
where Self: AsRef<CFType>,

👎Deprecated: this is redundant (CF types deref to CFType)
Helper for easier transition from the core-foundation crate.
Source§

unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self>
where Self: Sized,

👎Deprecated: use CFRetained::from_raw
Helper for easier transition from the core-foundation crate. Read more
Source§

impl Eq for CFError

Source§

impl Send for CFError

Source§

impl Sync for CFError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,