use std::{error::Error, fmt};
#[derive(Debug)]
pub struct EnumConversionError {
pub name: String,
pub requested_type: String,
}
impl EnumConversionError {
pub fn new(name: &str, requested_type: &str) -> EnumConversionError {
EnumConversionError {
name: name.to_string(),
requested_type: requested_type.to_string(),
}
}
}
impl Error for EnumConversionError {}
impl fmt::Display for EnumConversionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"EnumConversionError :: Active field of enum <{}> is not of type <{}>",
self.name, self.requested_type,
)
}
}
pub trait GetVariant<T, Marker> {
fn get_variant(self) -> Result<T, EnumConversionError>;
fn get_variant_ref(&self) -> Result<&T, EnumConversionError>;
fn get_variant_mut(&mut self) -> Result<&mut T, EnumConversionError>;
}
pub trait TryTo<T> {
type Error;
fn try_to(self) -> Result<T, Self::Error>;
}