Skip to content

Commit

Permalink
implement full eq/partial_eq for RegionParams
Browse files Browse the repository at this point in the history
This derives normal PartialEq and Eq for RegionParams but exposes a new eq_params function which checks  region parameter equality outside of the timestamp
  • Loading branch information
madninja committed Oct 18, 2023
1 parent d94ed4b commit ae6d2b0
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions beacon/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Region {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct RegionParams {
pub gain: Decimal,
pub region: Region,
Expand All @@ -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<GatewayRegionParamsResV1> for RegionParams {
type Error = Error;
fn try_from(value: GatewayRegionParamsResV1) -> Result<Self> {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit ae6d2b0

Please sign in to comment.