From dfc1511b25f66f60cccdae727e7b54946e2edcb6 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 20 Dec 2019 18:23:26 +0000 Subject: Use a named struct instead of a tuple in Expr --- dhall/src/syntax/ast/expr.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'dhall/src/syntax') 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(Box<(RawExpr, Span)>); +pub struct Expr { + kind: Box, Embed>>, + span: Span, +} pub type RawExpr = ExprKind, Embed>; @@ -230,21 +233,27 @@ impl ExprKind { impl Expr { pub fn as_ref(&self) -> &RawExpr { - &self.0.as_ref().0 + &self.kind } pub fn as_mut(&mut self) -> &mut RawExpr { - &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, n: Span) -> Self { - Expr(Box::new((x, n))) + pub fn new(kind: RawExpr, span: Span) -> Self { + Expr { + kind: Box::new(kind), + span, + } } - pub fn rewrap(&self, x: RawExpr) -> Expr { - Expr(Box::new((x, (self.0).1.clone()))) + pub fn rewrap(&self, kind: RawExpr) -> Expr { + Expr { + kind: Box::new(kind), + span: self.span.clone(), + } } pub fn traverse_resolve_mut( @@ -356,7 +365,7 @@ impl From