From d17d553a39aa3bffdfc19b7fe4801b85d6bd80f7 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 11 Apr 2019 16:41:06 +0200 Subject: Add lifetime parameters to Parsed and Resolved Future-proofing --- dhall/src/expr.rs | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'dhall/src/expr.rs') diff --git a/dhall/src/expr.rs b/dhall/src/expr.rs index 1ce20e3..e3a2fe5 100644 --- a/dhall/src/expr.rs +++ b/dhall/src/expr.rs @@ -1,5 +1,6 @@ use crate::imports::ImportRoot; use dhall_core::*; +use std::marker::PhantomData; macro_rules! derive_other_traits { ($ty:ident) => { @@ -20,13 +21,39 @@ macro_rules! derive_other_traits { }; } +macro_rules! derive_other_traits_ { + ($ty:ident) => { + impl<'a> std::cmp::PartialEq for $ty<'a> { + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } + } + + impl<'a> std::fmt::Display for $ty<'a> { + fn fmt( + &self, + f: &mut std::fmt::Formatter, + ) -> Result<(), std::fmt::Error> { + self.0.fmt(f) + } + } + }; +} + #[derive(Debug, Clone, Eq)] -pub struct Parsed(pub(crate) SubExpr, pub(crate) ImportRoot); -derive_other_traits!(Parsed); +pub struct Parsed<'a>( + pub(crate) SubExpr, + pub(crate) ImportRoot, + pub(crate) PhantomData<&'a ()>, +); +derive_other_traits_!(Parsed); #[derive(Debug, Clone, Eq)] -pub struct Resolved(pub(crate) SubExpr); -derive_other_traits!(Resolved); +pub struct Resolved<'a>( + pub(crate) SubExpr, + pub(crate) PhantomData<&'a ()>, +); +derive_other_traits_!(Resolved); #[derive(Debug, Clone, Eq)] pub struct Typed(pub(crate) SubExpr, pub(crate) Option); -- cgit v1.2.3