| David Tolnay | 1644873 | 2020-03-18 12:39:36 -0700 | [diff] [blame^] | 1 | use crate::syntax::{ExternFn, Ref, Signature, Ty1, Type}; |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 2 | use std::hash::{Hash, Hasher}; |
| David Tolnay | c21b20a | 2020-03-15 23:25:32 -0700 | [diff] [blame] | 3 | use std::mem; |
| David Tolnay | 1644873 | 2020-03-18 12:39:36 -0700 | [diff] [blame^] | 4 | use std::ops::Deref; |
| 5 | |
| 6 | impl Deref for ExternFn { |
| 7 | type Target = Signature; |
| 8 | |
| 9 | fn deref(&self) -> &Self::Target { |
| 10 | &self.sig |
| 11 | } |
| 12 | } |
| David Tolnay | c21b20a | 2020-03-15 23:25:32 -0700 | [diff] [blame] | 13 | |
| 14 | impl Hash for Type { |
| 15 | fn hash<H: Hasher>(&self, state: &mut H) { |
| 16 | mem::discriminant(self).hash(state); |
| 17 | match self { |
| 18 | Type::Ident(t) => t.hash(state), |
| 19 | Type::RustBox(t) => t.hash(state), |
| 20 | Type::UniquePtr(t) => t.hash(state), |
| 21 | Type::Ref(t) => t.hash(state), |
| 22 | Type::Str(t) => t.hash(state), |
| 23 | Type::Void(_) => {} |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | impl Eq for Type {} |
| 29 | |
| 30 | impl PartialEq for Type { |
| 31 | fn eq(&self, other: &Type) -> bool { |
| 32 | match (self, other) { |
| 33 | (Type::Ident(lhs), Type::Ident(rhs)) => lhs == rhs, |
| 34 | (Type::RustBox(lhs), Type::RustBox(rhs)) => lhs == rhs, |
| 35 | (Type::UniquePtr(lhs), Type::UniquePtr(rhs)) => lhs == rhs, |
| 36 | (Type::Ref(lhs), Type::Ref(rhs)) => lhs == rhs, |
| 37 | (Type::Str(lhs), Type::Str(rhs)) => lhs == rhs, |
| 38 | (Type::Void(_), Type::Void(_)) => true, |
| 39 | (_, _) => false, |
| 40 | } |
| 41 | } |
| 42 | } |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 43 | |
| 44 | impl Eq for Ty1 {} |
| 45 | |
| 46 | impl PartialEq for Ty1 { |
| 47 | fn eq(&self, other: &Ty1) -> bool { |
| 48 | self.name == other.name && self.inner == other.inner |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | impl Hash for Ty1 { |
| 53 | fn hash<H: Hasher>(&self, state: &mut H) { |
| 54 | self.name.hash(state); |
| 55 | self.inner.hash(state); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | impl Eq for Ref {} |
| 60 | |
| 61 | impl PartialEq for Ref { |
| 62 | fn eq(&self, other: &Ref) -> bool { |
| 63 | self.inner == other.inner |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl Hash for Ref { |
| 68 | fn hash<H: Hasher>(&self, state: &mut H) { |
| 69 | self.inner.hash(state); |
| 70 | } |
| 71 | } |