Fix Hash vs PartialEq bug found by Clippy

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
flip1995 2019-07-26 22:52:02 +02:00 committed by Matthias Beyer
parent 6ac6db57d1
commit 2c26fd2753

View file

@ -27,7 +27,7 @@ use failure::ResultExt;
use failure::Fallible as Result; use failure::Fallible as Result;
use failure::Error; use failure::Error;
#[derive(Eq, PartialOrd, Ord, Hash, Debug, Clone)] #[derive(Eq, PartialOrd, Ord, Debug, Clone)]
pub enum Link { pub enum Link {
Id { link: StoreId }, Id { link: StoreId },
LinkTo { link: StoreId }, LinkTo { link: StoreId },
@ -99,6 +99,17 @@ impl ::std::cmp::PartialEq for Link {
} }
} }
impl std::hash::Hash for Link {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
std::mem::discriminant(self).hash(state);
match &self {
Link::Id { link: a } => a.hash(state),
Link::LinkTo { link: a } => a.hash(state),
Link::LinkFrom { link: a } => a.hash(state),
}
}
}
impl From<StoreId> for Link { impl From<StoreId> for Link {
fn from(s: StoreId) -> Link { fn from(s: StoreId) -> Link {