From e08125a20c6c7ed6ba34d5b78005b34500d1975b Mon Sep 17 00:00:00 2001 From: Marc Nijdam Date: Wed, 18 Oct 2023 16:59:43 -0600 Subject: [PATCH 1/2] implement full eq/partial_eq for RegionParams This derives normal PartialEq and Eq for RegionParams but exposes a new eq_params function which checks region parameter equality outside of the timestamp --- beacon/src/region.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/beacon/src/region.rs b/beacon/src/region.rs index f5c027e3..bd23073c 100644 --- a/beacon/src/region.rs +++ b/beacon/src/region.rs @@ -86,7 +86,7 @@ impl Region { } } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct RegionParams { pub gain: Decimal, pub region: Region, @@ -102,12 +102,6 @@ impl AsRef<[BlockchainRegionParamV1]> for RegionParams { } } -impl PartialEq for RegionParams { - fn eq(&self, other: &Self) -> bool { - self.gain.eq(&other.gain) && self.region.eq(&other.region) && self.params.eq(&other.params) - } -} - impl TryFrom for RegionParams { type Error = Error; fn try_from(value: GatewayRegionParamsResV1) -> Result { @@ -155,6 +149,10 @@ impl RegionParams { } impl RegionParams { + pub fn eq_params(&self, other: &Self) -> bool { + self.gain.eq(&other.gain) && self.region.eq(&other.region) && self.params.eq(&other.params) + } + pub fn check_valid(&self) -> Result { if self.is_unknown() || self.params.is_empty() { return Err(Error::no_region_params()); From 622faee88e98083cdf10cb3de732ba4f50436062 Mon Sep 17 00:00:00 2001 From: Marc Nijdam Date: Wed, 18 Oct 2023 17:16:05 -0600 Subject: [PATCH 2/2] Fix deprecated from_i32 for proto enum --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7b65eed8..49702681 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -280,8 +280,8 @@ macro_rules! serde_enum { where S: serde::ser::Serializer, { - let v = $type::from_i32(*v) - .ok_or_else(|| serde::ser::Error::custom(format!("invalid enum value: {v}")))?; + let v = $type::try_from(*v) + .map_err(|_| serde::ser::Error::custom(format!("invalid enum value: {v}")))?; serializer.serialize_str(&v.to_string()) }