#![warn(missing_docs)]
use thiserror::Error;
#[derive(Error, Debug, Clone)]
#[error("expected {expected}, got {actual}")]
pub struct EnumExtractError {
pub expected: &'static str,
pub actual: &'static str,
}
impl EnumExtractError {
pub fn new(expected: &'static str, actual: &'static str) -> Self {
Self { expected, actual }
}
}
#[derive(Error, Debug)]
#[error("{source}")]
pub struct EnumExtractValueError<T> {
#[source]
pub source: EnumExtractError,
pub value: T,
}
impl<T> EnumExtractValueError<T> {
pub fn from_plain_error(extract_error: EnumExtractError, value: T) -> Self {
Self {
source: extract_error,
value,
}
}
pub fn new(expected: &'static str, actual: &'static str, value: T) -> Self {
Self {
source: EnumExtractError::new(expected, actual),
value,
}
}
}
impl<T> From<EnumExtractValueError<T>> for EnumExtractError {
fn from(value: EnumExtractValueError<T>) -> Self {
value.source
}
}