structured_pkix/path/
error.rs1use core::fmt;
4
5#[derive(Debug)]
13pub enum BuildError<V, R> {
14 Processing(crate::Error),
16 Verification(V),
18 Recognition(R),
20}
21
22pub type BuildResult<T, V, R> = core::result::Result<T, BuildError<V, R>>;
24
25impl<V, R> From<crate::Error> for BuildError<V, R> {
26 fn from(error: crate::Error) -> Self {
27 Self::Processing(error)
28 }
29}
30
31impl<V, R> From<crate::error::CallbackError<R>> for BuildError<V, R> {
32 fn from(error: crate::error::CallbackError<R>) -> Self {
33 match error {
34 crate::error::CallbackError::Processing(error) => Self::Processing(error),
35 crate::error::CallbackError::Callback(error) => Self::Recognition(error),
36 }
37 }
38}
39
40impl<V: fmt::Display, R: fmt::Display> fmt::Display for BuildError<V, R> {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 match self {
43 Self::Processing(error) => error.fmt(f),
44 Self::Verification(error) => write!(f, "signature verifier: {error}"),
45 Self::Recognition(error) => write!(f, "extension recognizer: {error}"),
46 }
47 }
48}
49
50#[cfg(feature = "std")]
51impl<V: std::error::Error + 'static, R: std::error::Error + 'static> std::error::Error
52 for BuildError<V, R>
53{
54 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
55 match self {
56 Self::Processing(error) => Some(error),
57 Self::Verification(error) => Some(error),
58 Self::Recognition(error) => Some(error),
59 }
60 }
61}