reorganize input format: make constructors lazy, parse members on get

This commit is contained in:
yggverse 2025-03-24 20:46:54 +02:00
parent 161142c809
commit a32eccf5cb
6 changed files with 243 additions and 85 deletions

View file

@ -1,23 +1,40 @@
use std::{
fmt::{Display, Formatter, Result},
str::Utf8Error,
};
use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
pub enum Error {
Default(super::default::Error),
FirstByte(u8),
Protocol,
Utf8Error(Utf8Error),
SecondByte(u8),
Sensitive(super::sensitive::Error),
UndefinedFirstByte,
UndefinedSecondByte,
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Utf8Error(e) => {
write!(f, "UTF-8 error: {e}")
Self::Default(e) => {
write!(f, "Default parse error: {e}")
}
Self::FirstByte(b) => {
write!(f, "Unexpected first byte: {b}")
}
Self::Protocol => {
write!(f, "Protocol error")
}
Self::SecondByte(b) => {
write!(f, "Unexpected second byte: {b}")
}
Self::Sensitive(e) => {
write!(f, "Sensitive parse error: {e}")
}
Self::UndefinedFirstByte => {
write!(f, "Undefined first byte")
}
Self::UndefinedSecondByte => {
write!(f, "Undefined second byte")
}
}
}
}