Skip to main content

zinq_schema/error/
mod.rs

1mod basic;
2mod field;
3mod group;
4
5pub use basic::*;
6pub use field::*;
7pub use group::*;
8
9#[derive(Debug, Clone)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub enum Error {
12    Basic(BasicError),
13    Field(FieldError),
14    Group(GroupError),
15}
16
17impl Error {
18    pub fn len(&self) -> usize {
19        return match self {
20            Self::Basic(v) => v.len(),
21            Self::Field(v) => v.len(),
22            Self::Group(v) => v.len(),
23        };
24    }
25}
26
27impl std::fmt::Display for Error {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        return match self {
30            Self::Basic(v) => write!(f, "{}", v),
31            Self::Field(v) => write!(f, "{}", v),
32            Self::Group(v) => write!(f, "{}", v),
33        };
34    }
35}
36
37impl std::error::Error for Error {
38    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
39        return match self {
40            Self::Basic(v) => v.source(),
41            Self::Field(v) => v.source(),
42            Self::Group(v) => v.source(),
43        };
44    }
45}