Skip to main content

apple_cf/
error.rs

1use core::fmt;
2
3/// Generic Core Foundation / Core Graphics creation error.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub struct CFError {
6    operation: &'static str,
7}
8
9impl CFError {
10    /// Create a new error for the named Core Foundation / Core Graphics call.
11    #[must_use]
12    pub const fn new(operation: &'static str) -> Self {
13        Self { operation }
14    }
15
16    /// The API call that failed.
17    #[must_use]
18    pub const fn operation(&self) -> &'static str {
19        self.operation
20    }
21}
22
23impl fmt::Display for CFError {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        write!(
26            f,
27            "{} returned a null Core Foundation/Core Graphics pointer",
28            self.operation
29        )
30    }
31}
32
33impl std::error::Error for CFError {}