summaryrefslogtreecommitdiff
path: root/dhall/src/syntax/ast
diff options
context:
space:
mode:
Diffstat (limited to 'dhall/src/syntax/ast')
-rw-r--r--dhall/src/syntax/ast/expr.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index 6ba6649..9e935dc 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;
+use crate::error::Error;
use crate::semantics::Universe;
use crate::syntax::map::{DupTreeMap, DupTreeSet};
use crate::syntax::visitor;
@@ -255,6 +256,13 @@ impl Expr {
span,
}
}
+
+ // Compute the sha256 hash of the binary form of the expression.
+ pub fn hash(&self) -> Result<Box<[u8]>, Error> {
+ use sha2::Digest;
+ let data = binary::encode(self)?;
+ Ok(sha2::Sha256::digest(&data).as_slice().into())
+ }
}
// Empty enum to indicate that no error can occur