chalk_engine/
derived.rs

1// These impls for PartialEq, Eq, etc are written by hand. This is
2// because the `#[derive()]` would add requirements onto the context
3// object that are not needed.
4
5use super::*;
6use std::cmp::{Eq, PartialEq};
7use std::hash::{Hash, Hasher};
8use std::mem;
9
10///////////////////////////////////////////////////////////////////////////
11
12impl<I: Interner> PartialEq for Literal<I> {
13    fn eq(&self, other: &Literal<I>) -> bool {
14        match (self, other) {
15            (Literal::Positive(goal1), Literal::Positive(goal2))
16            | (Literal::Negative(goal1), Literal::Negative(goal2)) => goal1 == goal2,
17
18            _ => false,
19        }
20    }
21}
22
23impl<I: Interner> Eq for Literal<I> {}
24
25impl<I: Interner> Hash for Literal<I> {
26    fn hash<H: Hasher>(&self, state: &mut H) {
27        mem::discriminant(self).hash(state);
28        match self {
29            Literal::Positive(goal) | Literal::Negative(goal) => {
30                goal.hash(state);
31            }
32        }
33    }
34}