Skip to content

Commit

Permalink
Use thiserror
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci committed Feb 20, 2023
1 parent 7089adb commit 68e9810
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
nom = "7"
nom = "7"
thiserror = "1.0"
21 changes: 6 additions & 15 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
use std::fmt::Display;
use thiserror::Error;

#[derive(Debug)]
#[derive(Debug, Error)]
pub enum Error {
#[error("Invalid Data")]
InvalidData,
#[error("Parse Error")]
ParseError,
#[error("Invalid Typecast")]
InvalidTypecast,
#[error("Not Implemented")]
NotImplemented,
}

impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let message = match &self {
Error::InvalidData => "InvalidData",
Error::ParseError => "ParseError",
Error::InvalidTypecast => "InvalidTypecast",
Error::NotImplemented => "NotImplemented",
};

f.write_str(message)
}
}

0 comments on commit 68e9810

Please sign in to comment.