From 60be2f39768c9f81d38c1aed89c982284e84a15a Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Sun, 17 Dec 2023 20:19:13 +0100 Subject: [PATCH] Implement the std::error::Error trait for ProviderError --- Cargo.toml | 2 +- src/providers.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f8c26175..a4d50df2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "urlshortener" -version = "3.0.2" +version = "3.1.0" edition = "2018" authors = ["Victor Polevoy "] description = "A very simple url shortener client library" diff --git a/src/providers.rs b/src/providers.rs index 672fbaa5..7e02d400 100644 --- a/src/providers.rs +++ b/src/providers.rs @@ -17,6 +17,17 @@ pub enum ProviderError { Deserialize, } +impl std::fmt::Display for ProviderError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match *self { + Self::Connection => write!(f, "A connection problem occured when connecting to a provided."), + Self::Deserialize => write!(f, "Couldn't deserialize the shortened URL from the response."), + } + } +} + +impl std::error::Error for ProviderError {} + /// A slice of all `Provider` variants which do not require authentication. /// This list is in order of provider quality. ///