summaryrefslogtreecommitdiff
path: root/dhall/src/phase/mod.rs
diff options
context:
space:
mode:
authorNadrieril2019-08-13 23:08:48 +0200
committerNadrieril2019-08-13 23:45:27 +0200
commitc600bae72198350b78fe19cf993b7f4c6f35225a (patch)
tree7986dc615d07a0a2d5b4ee5ff09a33164815ae5f /dhall/src/phase/mod.rs
parent43094c8c52319aa82b03e73700ca1b5f65da13c6 (diff)
Implement Hash for ParsedSubExpr
Diffstat (limited to '')
-rw-r--r--dhall/src/phase/mod.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs
index a1e3f29..b73597c 100644
--- a/dhall/src/phase/mod.rs
+++ b/dhall/src/phase/mod.rs
@@ -157,6 +157,10 @@ impl Typed {
}
impl Normalized {
+ pub fn encode(&self) -> Result<Vec<u8>, EncodeError> {
+ crate::phase::binary::encode(&self.to_expr())
+ }
+
#[allow(dead_code)]
pub fn to_expr(&self) -> NormalizedSubExpr {
self.0.to_expr()
@@ -220,6 +224,18 @@ derive_traits_for_wrapper_struct!(Parsed);
derive_traits_for_wrapper_struct!(Resolved);
derive_traits_for_wrapper_struct!(Normalized);
+impl std::hash::Hash for Normalized {
+ fn hash<H>(&self, state: &mut H)
+ where
+ H: std::hash::Hasher,
+ {
+ match self.encode() {
+ Ok(vec) => vec.hash(state),
+ Err(_) => {}
+ }
+ }
+}
+
impl Eq for Typed {}
impl PartialEq for Typed {
fn eq(&self, other: &Self) -> bool {