1#![allow(clippy::module_name_repetitions)]
2
3use std::{error::Error, fmt};
4
5use super::{Type, ARRAY_MAX};
6
7#[derive(Clone, PartialEq, Eq)]
9pub enum TypeError {
10 ArraySizeTooLarge(usize),
13 ArrayElemNotFilled,
15 NestedOption,
17 OptionNotFilled,
20 ParamNotFilled(usize),
23 VariadicNotFilled,
25 PairCarNotFilled,
27 PairCdrNotFilled,
29 UnionNotSpecific(Type),
31 UnionTooFewMembers,
33}
34
35impl Error for TypeError {}
36
37impl fmt::Display for TypeError {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 match self {
40 Self::ArraySizeTooLarge(size) => {
41 write!(f, "array size exceeds maximum of {ARRAY_MAX}: {size}")
42 }
43 Self::ArrayElemNotFilled => write!(f, "array element type is not filled or an option"),
44 Self::NestedOption => write!(f, "nested option types are not supported"),
45 Self::OptionNotFilled => write!(f, "option type is not filled"),
46 Self::ParamNotFilled(idx) => {
47 write!(f, "parameter {idx} type is not filled or an option")
48 }
49 Self::VariadicNotFilled => write!(f, "variadic type is not filled or an option"),
50 Self::PairCarNotFilled => write!(f, "pair car type is not filled or an option"),
51 Self::PairCdrNotFilled => write!(f, "pair cdr type is not filled or an option"),
52 Self::UnionNotSpecific(ty) => {
53 write!(f, "union type must contain only specific types, got: {ty}")
54 }
55 Self::UnionTooFewMembers => write!(f, "union type must contain at least two members"),
56 }
57 }
58}
59
60impl fmt::Debug for TypeError {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 fmt::Display::fmt(self, f)
63 }
64}