derive_getters/
faultmsg.rs

1//! Error type. 
2use std::fmt;
3
4#[derive(Debug)]
5#[allow(dead_code)]
6pub enum StructIs {
7    Unnamed,
8    Enum,
9    Union,
10    Unit,
11}
12
13impl fmt::Display for StructIs {
14    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15        match self {
16            Self::Unnamed => write!(f, "an unnamed struct"),
17            Self::Enum => write!(f, "an enum"),
18            Self::Union => write!(f, "a union"),
19            Self::Unit => write!(f, "a unit struct"),
20        }
21    }
22}
23
24// Almost an error type! But `syn` already has an error type so this just fills the
25// `T: Display` part to avoid strings littering the source.
26#[derive(Debug)]
27#[allow(dead_code)]
28pub enum Problem {
29    NotNamedStruct(StructIs),
30    UnnamedField,
31    InnerAttribute,
32    EmptyAttribute,
33    NoGrouping,
34    NonParensGrouping,
35    EmptyGrouping,
36    TokensFollowSkip,
37    TokensFollowNewName,
38    InvalidAttribute,
39    BotchedDocComment,
40}
41
42impl fmt::Display for Problem {
43    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44        match self {
45            Self::NotNamedStruct(is) => {
46                write!(f, "type must be a named struct, not {}", is)
47            },
48            Self::UnnamedField => write!(f, "struct fields must be named"),
49            Self::InnerAttribute => {
50                write!(f, "attribute is an outer not inner attribute")
51            },
52            Self::EmptyAttribute => write!(f, "attribute has no tokens"),
53            Self::NoGrouping => write!(f, "attribute tokens must be grouped"),
54            Self::NonParensGrouping => {
55                write!(f, "attribute tokens must be within parenthesis")
56            },
57            Self::EmptyGrouping => {
58                write!(f, "no attribute tokens within parenthesis grouping")
59            },
60            Self::TokensFollowSkip => {
61                write!(f, "tokens are not meant to follow skip attribute")
62            },
63            Self::TokensFollowNewName => {
64                write!(f, "no further tokens must follow new name")
65            },
66            Self::InvalidAttribute => {
67                write!(f, "invalid attribute")
68            },
69            Self::BotchedDocComment => {
70                write!(f, "Doc comment is botched")
71            },
72        }
73    }
74}