Skip to content

Commit

Permalink
Manual implementation of PartialEq for Code
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Jul 7, 2024
1 parent 728ee56 commit 45f07d7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/country.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use serde_derive::{Deserialize, Serialize};
use std::str;
use strum::{AsRefStr, EnumString};

#[derive(Copy, Clone, Eq, PartialEq, Serialize, Deserialize, Hash, Debug)]
#[derive(Copy, Clone, Serialize, Deserialize, Hash, Debug)]

Check failure on line 21 in src/country.rs

View workflow job for this annotation

GitHub Actions / clippy

you are deriving `Hash` but have implemented `PartialEq` explicitly
pub struct Code {
/// The country code value.
pub(crate) value: u16,
Expand All @@ -27,6 +27,18 @@ pub struct Code {
pub(crate) source: Source,
}

impl PartialEq for Code {
/// Compare two country codes.
///
/// This implementation is necessary because the `source` field is not
/// relevant for equality.
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}

impl Eq for Code {}

/// The source from which the country code is derived. This is not set in the
/// general parsing method, but in the method that parses and keeps raw_input.
#[derive(Eq, PartialEq, Copy, Clone, Serialize, Deserialize, Hash, Debug)]
Expand Down

0 comments on commit 45f07d7

Please sign in to comment.