Better Hash and PartialEq for Keys and AnchoredKeys (#277)
This commit is contained in:
parent
273d803ebd
commit
3ea0d5be71
1 changed files with 27 additions and 2 deletions
|
|
@ -443,7 +443,7 @@ impl From<&Value> for Hash {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Debug, Eq)]
|
||||
pub struct Key {
|
||||
name: String,
|
||||
hash: Hash,
|
||||
|
|
@ -466,6 +466,18 @@ impl Key {
|
|||
}
|
||||
}
|
||||
|
||||
impl hash::Hash for Key {
|
||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||
self.hash.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Key {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.hash == other.hash
|
||||
}
|
||||
}
|
||||
|
||||
// A Key can easily be created from a string-like type
|
||||
impl<T> From<T> for Key
|
||||
where
|
||||
|
|
@ -531,7 +543,7 @@ impl JsonSchema for Key {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
|
||||
#[derive(Clone, Debug, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AnchoredKey {
|
||||
pub pod_id: PodId,
|
||||
|
|
@ -544,6 +556,19 @@ impl AnchoredKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl hash::Hash for AnchoredKey {
|
||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||
self.pod_id.hash(state);
|
||||
self.key.hash.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for AnchoredKey {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.pod_id == other.pod_id && self.key.hash == other.key.hash
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for AnchoredKey {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.pod_id.fmt(f)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue