Skip to main content

ashlar_native/
error.rs

1/// Why a native call did not do what was asked.
2#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
3pub enum NativeError {
4    /// Not available on this platform, in this build, or in this process (for example
5    /// notifications from an unbundled macOS binary). Callers treat it as "skip the feature".
6    #[error("not supported on this platform")]
7    Unsupported,
8    /// The OS or the user refused (keychain locked, permission not granted).
9    #[error("denied: {0}")]
10    Denied(String),
11    /// The user dismissed a dialog.
12    #[error("cancelled")]
13    Cancelled,
14    /// The caller passed something unusable (an invalid accelerator, a URL with a forbidden scheme).
15    #[error("invalid: {0}")]
16    Invalid(String),
17    /// The OS reported a failure; the text is one line and safe to show.
18    #[error("{0}")]
19    Os(String),
20}
21
22pub type Result<T, E = NativeError> = std::result::Result<T, E>;
23
24impl NativeError {
25    pub fn is_unsupported(&self) -> bool {
26        matches!(self, Self::Unsupported)
27    }
28}