Skip to main content

apple_log/
error.rs

1//! Errors returned by the `apple-log` crate.
2
3use core::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6#[non_exhaustive]
7pub enum LogError {
8    /// An argument contained a NUL byte and could not cross the FFI boundary.
9    InvalidArgument(String),
10    /// A constructor unexpectedly returned a null handle.
11    CreateFailed,
12    /// The Swift bridge or wrapped Apple API returned a human-readable error.
13    BridgeError(String),
14}
15
16impl LogError {
17    pub(crate) fn bridge(message: impl Into<String>) -> Self {
18        Self::BridgeError(message.into())
19    }
20}
21
22impl fmt::Display for LogError {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Self::InvalidArgument(message) => write!(f, "invalid argument: {message}"),
26            Self::CreateFailed => write!(f, "bridge constructor returned NULL"),
27            Self::BridgeError(message) => write!(f, "bridge error: {message}"),
28        }
29    }
30}
31
32impl std::error::Error for LogError {}