summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
authorNadrieril2019-12-20 18:23:26 +0000
committerNadrieril2019-12-20 18:41:41 +0000
commitdfc1511b25f66f60cccdae727e7b54946e2edcb6 (patch)
tree0937ab033f0468f16326cb12a3fc9399fedb0068 /dhall/src
parent99a2fdf5bf92d051d154c24ce95c444bccb30609 (diff)
Use a named struct instead of a tuple in Expr
Diffstat (limited to '')
-rw-r--r--dhall/src/syntax/ast/expr.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs
index 9f19ddb..93c2311 100644
--- a/dhall/src/syntax/ast/expr.rs
+++ b/dhall/src/syntax/ast/expr.rs
@@ -94,7 +94,10 @@ pub enum Builtin {
// Each node carries an annotation.
#[derive(Debug, Clone)]
-pub struct Expr<Embed>(Box<(RawExpr<Embed>, Span)>);
+pub struct Expr<Embed> {
+ kind: Box<ExprKind<Expr<Embed>, Embed>>,
+ span: Span,
+}
pub type RawExpr<Embed> = ExprKind<Expr<Embed>, Embed>;
@@ -230,21 +233,27 @@ impl<SE, E> ExprKind<SE, E> {
impl<E> Expr<E> {
pub fn as_ref(&self) -> &RawExpr<E> {
- &self.0.as_ref().0
+ &self.kind
}
pub fn as_mut(&mut self) -> &mut RawExpr<E> {
- &mut self.0.as_mut().0
+ &mut self.kind
}
pub fn span(&self) -> Span {
- self.0.as_ref().1.clone()
+ self.span.clone()
}
- pub fn new(x: RawExpr<E>, n: Span) -> Self {
- Expr(Box::new((x, n)))
+ pub fn new(kind: RawExpr<E>, span: Span) -> Self {
+ Expr {
+ kind: Box::new(kind),
+ span,
+ }
}
- pub fn rewrap<E2>(&self, x: RawExpr<E2>) -> Expr<E2> {
- Expr(Box::new((x, (self.0).1.clone())))
+ pub fn rewrap<E2>(&self, kind: RawExpr<E2>) -> Expr<E2> {
+ Expr {
+ kind: Box::new(kind),
+ span: self.span.clone(),
+ }
}
pub fn traverse_resolve_mut<Err, F1>(
@@ -356,7 +365,7 @@ impl From<Label> for V<Label> {
impl<Embed: PartialEq> std::cmp::PartialEq for Expr<Embed> {
fn eq(&self, other: &Self) -> bool {
- self.0.as_ref().0 == other.0.as_ref().0
+ self.kind == other.kind
}
}
@@ -367,6 +376,6 @@ impl<Embed: std::hash::Hash> std::hash::Hash for Expr<Embed> {
where
H: std::hash::Hasher,
{
- (self.0).0.hash(state)
+ self.kind.hash(state)
}
}