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    UnitStruct,
32    InnerAttribute,
33    EmptyAttribute,
34    NoGrouping,
35    NonParensGrouping,
36    EmptyGrouping,
37    TokensFollowSkip,
38    TokensFollowCopy,
39    TokensFollowNewName,
40    InvalidAttribute,
41    BotchedDocComment,
42}
43
44impl fmt::Display for Problem {
45    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46        match self {
47            Self::NotNamedStruct(is) => {
48                write!(f, "type must be a named struct, not {}", is)
49            }
50            Self::UnnamedField => write!(f, "struct fields must be named"),
51            Self::UnitStruct => write!(f, "unit struct has nothing to dissolve"),
52            Self::InnerAttribute => {
53                write!(f, "attribute is an outer not inner attribute")
54            }
55            Self::EmptyAttribute => write!(f, "attribute has no tokens"),
56            Self::NoGrouping => write!(f, "attribute tokens must be grouped"),
57            Self::NonParensGrouping => {
58                write!(f, "attribute tokens must be within parenthesis")
59            }
60            Self::EmptyGrouping => {
61                write!(f, "no attribute tokens within parenthesis grouping")
62            }
63            Self::TokensFollowSkip => {
64                write!(f, "tokens are not meant to follow skip attribute")
65            }
66            Self::TokensFollowCopy => {
67                write!(f, "tokens are not meant to follow copy attribute")
68            }
69            Self::TokensFollowNewName => {
70                write!(f, "no further tokens must follow new name")
71            }
72            Self::InvalidAttribute => {
73                write!(f, "invalid attribute")
74            }
75            Self::BotchedDocComment => {
76                write!(f, "Doc comment is botched")
77            }
78        }
79    }
80}