aboutsummaryrefslogtreecommitdiff
path: root/src/bt.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2019-12-12 02:16:27 +0100
committerDaniel Schadt <kingdread@gmx.de>2019-12-12 02:16:27 +0100
commit3c92e88164db6a94177fb4adeb18c80dffc377e4 (patch)
treec2fdefbe04901df614a9753093d146f424d42a9c /src/bt.rs
parenta6afa81d1d9f2dd7d10fe7c0555ae8a8a6d84867 (diff)
downloadkondou-3c92e88164db6a94177fb4adeb18c80dffc377e4.tar.gz
kondou-3c92e88164db6a94177fb4adeb18c80dffc377e4.tar.bz2
kondou-3c92e88164db6a94177fb4adeb18c80dffc377e4.zip
remove quick_error
quick_error used the deprecated Error::cause interface, therefore we want to use our own error enums with proper methods.
Diffstat (limited to 'src/bt.rs')
-rw-r--r--src/bt.rs43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/bt.rs b/src/bt.rs
index 21078ff..cf95f3c 100644
--- a/src/bt.rs
+++ b/src/bt.rs
@@ -1,20 +1,35 @@
use super::api::{Api, ApiError, Skill, Specialization};
use num_enum::{IntoPrimitive, TryFromPrimitive};
-use std::{convert::TryFrom, fmt, str::FromStr};
-
-quick_error! {
- #[derive(Debug)]
- pub enum ChatlinkError {
- ApiError(err: ApiError) {
- cause(err)
- from()
+use std::{convert::TryFrom, error::Error, fmt, str::FromStr};
+
+#[derive(Debug)]
+pub enum ChatlinkError {
+ ApiError(ApiError),
+ MalformedInput,
+}
+
+error_froms! { ChatlinkError,
+ err: ApiError => ChatlinkError::ApiError(err),
+ _err: base64::DecodeError => ChatlinkError::MalformedInput,
+ _err: num_enum::TryFromPrimitiveError<Profession> => ChatlinkError::MalformedInput,
+ _err: num_enum::TryFromPrimitiveError<TraitChoice> => ChatlinkError::MalformedInput,
+ _err: num_enum::TryFromPrimitiveError<Legend> => ChatlinkError::MalformedInput,
+}
+
+impl fmt::Display for ChatlinkError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ ChatlinkError::ApiError(_) => write!(f, "error accessing the API"),
+ ChatlinkError::MalformedInput => write!(f, "the input link is malformed"),
}
- MalformedInput {
- description("The input link is malformed")
- from(base64::DecodeError)
- from(num_enum::TryFromPrimitiveError<Profession>)
- from(num_enum::TryFromPrimitiveError<TraitChoice>)
- from(num_enum::TryFromPrimitiveError<Legend>)
+ }
+}
+
+impl Error for ChatlinkError {
+ fn source(&self) -> Option<&(dyn Error + 'static)> {
+ match *self {
+ ChatlinkError::ApiError(ref err) => Some(err),
+ _ => None,
}
}
}