1
Fork 0
mirror of https://github.com/Steffo99/patched-porobot.git synced 2024-12-22 17:44:22 +00:00

Make Cards Eq based on their Card::code

This commit is contained in:
Steffo 2022-08-22 18:13:23 +02:00
parent ad748c0346
commit 89a1eefd25
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -16,7 +16,7 @@ use super::code::CardCode;
/// A single Legends of Runeterra card, as represented in a `set*.json` file. /// A single Legends of Runeterra card, as represented in a `set*.json` file.
/// ///
/// The data is available in a developer-friendly interface, but nevertheless it can be serialized and deserialized via [serde] in the exact same format used in the `set*.json` files. /// The data is available in a developer-friendly interface, but nevertheless it can be serialized and deserialized via [serde] in the exact same format used in the `set*.json` files.
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[derive(Clone, Debug, Eq, serde::Serialize, serde::Deserialize)]
pub struct Card { pub struct Card {
/// Unique seven-character identifier of the card. /// Unique seven-character identifier of the card.
#[serde(rename = "cardCode")] #[serde(rename = "cardCode")]
@ -162,7 +162,19 @@ impl Card {
} }
/// Card [`Hash`]es are equal to hashes of their [`Card::code`]. /// Two [`Card`]s are equal if they have the same [`Card::code`].
impl PartialEq for Card {
fn eq(&self, other: &Self) -> bool {
self.code == other.code
}
fn ne(&self, other: &Self) -> bool {
self.code != other.code
}
}
/// [`Card`] [`Hash`]es are equal to hashes of their [`Card::code`].
impl Hash for Card { impl Hash for Card {
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
self.code.hash(state) self.code.hash(state)