use core::fmt;
#[derive(Debug)]
pub enum BuildError<V, R> {
Processing(crate::Error),
Verification(V),
Recognition(R),
}
pub type BuildResult<T, V, R> = core::result::Result<T, BuildError<V, R>>;
impl<V, R> From<crate::Error> for BuildError<V, R> {
fn from(error: crate::Error) -> Self {
Self::Processing(error)
}
}
impl<V, R> From<crate::error::CallbackError<R>> for BuildError<V, R> {
fn from(error: crate::error::CallbackError<R>) -> Self {
match error {
crate::error::CallbackError::Processing(error) => Self::Processing(error),
crate::error::CallbackError::Callback(error) => Self::Recognition(error),
}
}
}
impl<V: fmt::Display, R: fmt::Display> fmt::Display for BuildError<V, R> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Processing(error) => error.fmt(f),
Self::Verification(error) => write!(f, "signature verifier: {error}"),
Self::Recognition(error) => write!(f, "extension recognizer: {error}"),
}
}
}
#[cfg(feature = "std")]
impl<V: std::error::Error + 'static, R: std::error::Error + 'static> std::error::Error
for BuildError<V, R>
{
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Processing(error) => Some(error),
Self::Verification(error) => Some(error),
Self::Recognition(error) => Some(error),
}
}
}