Skip to content

Commit

Permalink
feat: add PartialEq to StarknetApiError (#296)
Browse files Browse the repository at this point in the history
This will mainly help test writers, who can now `assert_eq!` on
`StarknetApiResult`s.

Co-Authored-By: Gilad Chase <gilad@starkware.com>
  • Loading branch information
giladchase and Gilad Chase authored Jul 14, 2024
1 parent 03d4a9f commit 0b49c07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
10 changes: 9 additions & 1 deletion src/serde_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ impl<const N: usize, const PREFIXED: bool> Serialize for BytesAsHex<N, PREFIXED>
}

/// 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)]
Expand Down

0 comments on commit 0b49c07

Please sign in to comment.