From 2a5cd8330287d443b9ca329ef76e873797cf3065 Mon Sep 17 00:00:00 2001 From: diogo464 Date: Tue, 10 Oct 2023 18:41:34 +0100 Subject: [PATCH 1/2] fix: impl error for Error --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8bcebea..ebc9a6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,8 @@ pub enum Error { BlocklistMaxAttempts, } +impl std::error::Error for Error {} + pub type Result = result::Result; pub fn default_blocklist() -> HashSet { From 95ad5d1bc38516fec0dfcca3331afbb0b60e2d3d Mon Sep 17 00:00:00 2001 From: diogo464 Date: Tue, 10 Oct 2023 18:49:45 +0100 Subject: [PATCH 2/2] use thiserror instead --- Cargo.toml | 2 +- src/lib.rs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dd5c20d..984a3bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,6 @@ readme = "README.md" keywords = ["ids", "encode", "short", "sqids", "hashids"] [dependencies] -derive_more = "0.99.17" serde = "1.0.188" serde_json = "1.0.107" +thiserror = "1.0.49" diff --git a/src/lib.rs b/src/lib.rs index ebc9a6b..89b9c58 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,20 +1,19 @@ -use derive_more::Display; use std::{cmp::min, collections::HashSet, result}; -#[derive(Display, Debug, Eq, PartialEq)] +use thiserror::Error; + +#[derive(Error, Debug, Eq, PartialEq)] pub enum Error { - #[display(fmt = "Alphabet cannot contain multibyte characters")] + #[error("Alphabet cannot contain multibyte characters")] AlphabetMultibyteCharacters, - #[display(fmt = "Alphabet length must be at least 3")] + #[error("Alphabet length must be at least 3")] AlphabetLength, - #[display(fmt = "Alphabet must contain unique characters")] + #[error("Alphabet must contain unique characters")] AlphabetUniqueCharacters, - #[display(fmt = "Reached max attempts to re-generate the ID")] + #[error("Reached max attempts to re-generate the ID")] BlocklistMaxAttempts, } -impl std::error::Error for Error {} - pub type Result = result::Result; pub fn default_blocklist() -> HashSet {