#![allow(clippy::module_name_repetitions)]
use std::{error::Error, fmt};
use super::{Type, ARRAY_MAX};
#[derive(Clone, PartialEq, Eq)]
pub enum TypeError {
ArraySizeTooLarge(usize),
ArrayElemNotFilled,
NestedOption,
OptionNotFilled,
ParamNotFilled(usize),
VariadicNotFilled,
PairCarNotFilled,
PairCdrNotFilled,
UnionNotSpecific(Type),
UnionTooFewMembers,
}
impl Error for TypeError {}
impl fmt::Display for TypeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ArraySizeTooLarge(size) => {
write!(f, "array size exceeds maximum of {ARRAY_MAX}: {size}")
}
Self::ArrayElemNotFilled => write!(f, "array element type is not filled or an option"),
Self::NestedOption => write!(f, "nested option types are not supported"),
Self::OptionNotFilled => write!(f, "option type is not filled"),
Self::ParamNotFilled(idx) => {
write!(f, "parameter {idx} type is not filled or an option")
}
Self::VariadicNotFilled => write!(f, "variadic type is not filled or an option"),
Self::PairCarNotFilled => write!(f, "pair car type is not filled or an option"),
Self::PairCdrNotFilled => write!(f, "pair cdr type is not filled or an option"),
Self::UnionNotSpecific(ty) => {
write!(f, "union type must contain only specific types, got: {ty}")
}
Self::UnionTooFewMembers => write!(f, "union type must contain at least two members"),
}
}
}
impl fmt::Debug for TypeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}