1use std::fmt;
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum InvalidNameError {
7 #[error("cannot be empty")]
8 Empty,
9 #[error("cannot contain characters that are not part of the extended ASCII set")]
10 NonAscii,
11 #[error("cannot start with a non-letter ASCII character")]
12 NonAsciiAlphabeticFirstChar,
13 #[error("cannot end with a non-letter or non-digit ASCII character")]
14 NonAsciiAlphanumericLastChar,
15}
16
17#[derive(Error, Debug)]
18pub enum InvalidValueError {
19 #[error("cannot contain characters that are not part of the extended ASCII set")]
20 NonExtendedAscii,
21 #[error("cannot contain ASCII control characters")]
22 ContainsControlChar,
23}
24
25#[derive(Error, Debug)]
26pub enum AttributeError {
28 #[error("Invalid attribute name: {0}")]
30 InvalidName(#[from] InvalidNameError),
31 #[error("Invalid attribute value: {0}")]
33 InvalidValue(#[from] InvalidValueError),
34}
35
36#[derive(Error, Debug)]
56pub struct ParseError(String);
57
58impl fmt::Display for ParseError {
59 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
60 write!(f, "{}", self.0)
61 }
62}
63
64impl From<winnow::error::ParseError<&str, winnow::error::ContextError>> for ParseError {
65 fn from(value: winnow::error::ParseError<&str, winnow::error::ContextError>) -> Self {
66 Self(value.to_string())
67 }
68}