Skip to content

Commit

Permalink
use thiserror attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
femshima committed Feb 28, 2024
1 parent 52f926e commit 73db0be
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions src/model/parser/header/error.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
use std::fmt::{self, Display};
use std::fmt::Display;

#[derive(Debug, thiserror::Error)]
pub enum DeserializeError {
#[error("{0}")]
Message(String),

#[error("unexpected end of input")]
Eof,
#[error("expected bool (0 or 1)")]
ExpectedBool,
#[error("expected integer value")]
ExpectedInteger,
#[error("expected comma as an array delimiter")]
ExpectedArrayComma,
#[error("expected colon as map delimiter")]
ExpectedMapColon,
#[error("expected newline as map delimiter")]
ExpectedMapNewline,
#[error("some characters were not consumed")]
TrailingCharacters,
}

Expand All @@ -18,27 +26,3 @@ impl serde::de::Error for DeserializeError {
DeserializeError::Message(msg.to_string())
}
}

impl Display for DeserializeError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self {
DeserializeError::Message(msg) => formatter.write_str(msg),

DeserializeError::Eof => formatter.write_str("unexpected end of input"),
DeserializeError::ExpectedBool => formatter.write_str("expected bool (0 or 1)"),
DeserializeError::ExpectedInteger => formatter.write_str("expected integer value"),
DeserializeError::ExpectedArrayComma => {
formatter.write_str("expected comma as an array delimiter")
}
DeserializeError::ExpectedMapColon => {
formatter.write_str("expected colon as map delimiter")
}
DeserializeError::ExpectedMapNewline => {
formatter.write_str("expected newline as map delimiter")
}
DeserializeError::TrailingCharacters => {
formatter.write_str("some characters were not consumed")
}
}
}
}

0 comments on commit 73db0be

Please sign in to comment.