From 7b422010d7665edab27f91fcd0b417b4c147d38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Marques?= Date: Sat, 7 Sep 2024 22:03:06 +0100 Subject: [PATCH] Manually implement fmt::Display and drop dependency on derive_more --- Cargo.toml | 1 - src/error.rs | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 475a409..924482c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ serde_json = "1.0" reqwest = { version = "0.12", default-features = false } chrono = { version = "0.4", features = ["serde"] } chrono-tz = "0.8" -derive_more = "0.99" [features] default = ["reqwest/native-tls"] diff --git a/src/error.rs b/src/error.rs index 61c374d..5e260ec 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,22 +1,27 @@ -use derive_more::Display; - /// Set of errors which can occur when calling the API. -#[derive(Display, Debug)] +#[derive(Debug)] pub enum Error { /// Error establishing a network connection. - #[display(fmt = "connection error: {}", _0)] ConnectionError(String), /// HTTP error returned by the API. - #[display(fmt = "server returned HTTP status code {}", _0)] ServerError(u16), /// Error parsing the API response. - #[display(fmt = "parsing error: {}", _0)] ParsingError(String), /// Error returned by the API. - #[display(fmt = "API error: {}", _0)] APIError(String), } +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::ConnectionError(e) => write!(f, "connection error: {}", e), + Error::ServerError(e) => write!(f, "server returned HTTP status code {}", e), + Error::ParsingError(e) => write!(f, "parsing error: {}", e), + Error::APIError(e) => write!(f, "API error: {}", e), + } + } +} + impl std::error::Error for Error {} impl From for Error {