From 0b49c078933f21a37e19b4bf1b198db60d63995d Mon Sep 17 00:00:00 2001 From: giladchase Date: Sun, 14 Jul 2024 15:54:42 +0300 Subject: [PATCH] feat: add PartialEq to StarknetApiError (#296) This will mainly help test writers, who can now `assert_eq!` on `StarknetApiResult`s. Co-Authored-By: Gilad Chase --- src/lib.rs | 3 ++- src/serde_utils.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7196b3d0..8700b8e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,8 @@ use std::num::ParseIntError; use serde_utils::InnerDeserializationError; /// The error type returned by StarknetApi. -#[derive(thiserror::Error, Clone, Debug)] +// Note: if you need `Eq` see InnerDeserializationError's docstring. +#[derive(thiserror::Error, Clone, Debug, PartialEq)] pub enum StarknetApiError { /// Error in the inner deserialization of the node. #[error(transparent)] diff --git a/src/serde_utils.rs b/src/serde_utils.rs index 52144e41..c23b7f4e 100644 --- a/src/serde_utils.rs +++ b/src/serde_utils.rs @@ -76,7 +76,15 @@ impl Serialize for BytesAsHex } /// The error type returned by the inner deserialization. -#[derive(thiserror::Error, Clone, Debug)] +// If you need `eq`, add `impl Eq fro InnerDeserializationError {}` and read warning below. +// +// For some reason `hex` (now unmaintained for > 3 years) didn't implement `Eq`, even though +// there's no reason not too, so we can't use `derive(Eq)` unfortunately. +// Note that adding the impl is risky, because if at some point `hex` decide to add non-Eq +// things to the error, then combined with the manual `impl Eq` this will create very nasty bugs. +// So, for prudence, we'll hold off on adding `Eq` until we have a good reason to. +// Existing (ignored) issue on this: https://github.com/KokaKiwi/rust-hex/issues/76. +#[derive(thiserror::Error, Clone, Debug, PartialEq)] pub enum InnerDeserializationError { /// Error parsing the hex string. #[error(transparent)]