Skip to main content

structured_pkix/error/
callback.rs

1//! Processing failures and the original error of an injected callback.
2
3use core::fmt;
4
5/// A callback-backed query that could not finish.
6///
7/// The wrapper allocates no storage. Any owned callback error data must retain
8/// its own resource accounting until it is dropped.
9#[derive(Debug)]
10pub enum CallbackError<E> {
11    /// Shared processing failed, including a located resource refusal.
12    Processing(super::Error),
13    /// The caller's callback failed, preserving its original cause.
14    Callback(E),
15}
16
17impl<E> From<super::Error> for CallbackError<E> {
18    fn from(error: super::Error) -> Self {
19        Self::Processing(error)
20    }
21}
22
23impl<E: fmt::Display> fmt::Display for CallbackError<E> {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            Self::Processing(error) => error.fmt(f),
27            Self::Callback(error) => write!(f, "callback: {error}"),
28        }
29    }
30}
31
32#[cfg(feature = "std")]
33impl<E: std::error::Error + 'static> std::error::Error for CallbackError<E> {
34    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
35        match self {
36            Self::Processing(error) => Some(error),
37            Self::Callback(error) => Some(error),
38        }
39    }
40}
41
42/// Result of shared processing that can invoke a fallible callback.
43pub type CallbackResult<T, E> = core::result::Result<T, CallbackError<E>>;