diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-04-04 13:48:56 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-04-04 13:55:20 +0200 |
commit | 4ec62bbac872bbfd95413af2f00c3f4a36c70630 (patch) | |
tree | 22cac1ff6f9776565d9f35322c463ec6125c0bc7 /src/raw | |
parent | 22738da2cd36b4ae2e1fb5efd23373e6b77405a2 (diff) | |
download | evtclib-4ec62bbac872bbfd95413af2f00c3f4a36c70630.tar.gz evtclib-4ec62bbac872bbfd95413af2f00c3f4a36c70630.tar.bz2 evtclib-4ec62bbac872bbfd95413af2f00c3f4a36c70630.zip |
switch from quick_error to thiserror
thiserror seems to be the more modern approach that also works with the
new Error trait from std.
Diffstat (limited to 'src/raw')
-rw-r--r-- | src/raw/parser.rs | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/src/raw/parser.rs b/src/raw/parser.rs index fa3b36c..0e91f78 100644 --- a/src/raw/parser.rs +++ b/src/raw/parser.rs @@ -65,6 +65,7 @@ use byteorder::{LittleEndian, ReadBytesExt, LE}; use num_traits::FromPrimitive; +use thiserror::Error; use std::io::{self, ErrorKind, Read}; use super::*; @@ -107,38 +108,25 @@ pub struct PartialEvtc { pub skills: Vec<Skill>, } -quick_error! { - #[derive(Debug)] - pub enum ParseError { - Io(err: io::Error) { - from() - description("io error") - display("I/O error: {}", err) - cause(err) - } - Utf8Error(err: ::std::string::FromUtf8Error) { - from() - description("utf8 decoding error") - display("UTF-8 decoding error: {}", err) - cause(err) - } - InvalidData { - from(::std::option::NoneError) - description("invalid data") - } - MalformedHeader { - description("malformed header") - } - UnknownRevision(rev: u8) { - description("unknown revision") - display("revision number not known: {}", rev) - } - InvalidZip(err: ::zip::result::ZipError) { - from() - description("zip error") - display("Archive error: {}", err) - cause(err) - } +#[derive(Error, Debug)] +pub enum ParseError { + #[error("IO error: {0}")] + Io(#[from] io::Error), + #[error("utf8 decoding error: {0}")] + Utf8Error(#[from] std::string::FromUtf8Error), + #[error("invalid data")] + InvalidData, + #[error("malformed header")] + MalformedHeader, + #[error("unknown revision: {0}")] + UnknownRevision(u8), + #[error("invalid archive: {0}")] + InvalidZip(#[from] zip::result::ZipError), +} + +impl From<std::option::NoneError> for ParseError { + fn from(_: std::option::NoneError) -> Self { + ParseError::InvalidData } } |