From 4bebcd96b6e76b9b8ae7877af91d2ae571e617a9 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 7 Apr 2019 16:45:30 +0200 Subject: Restrict public API Closes #20 --- dhall/src/expr.rs | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'dhall/src/expr.rs') diff --git a/dhall/src/expr.rs b/dhall/src/expr.rs index 555db2f..7baf628 100644 --- a/dhall/src/expr.rs +++ b/dhall/src/expr.rs @@ -1,34 +1,46 @@ use crate::imports::ImportRoot; use dhall_core::*; +macro_rules! derive_other_traits { + ($ty:ident) => { + impl std::cmp::PartialEq for $ty { + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } + } + + impl std::fmt::Display for $ty { + 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); -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, Eq)] pub struct Resolved(pub(crate) SubExpr); +derive_other_traits!(Resolved); -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Eq)] pub struct Typed(pub(crate) SubExpr, pub(crate) Type); +derive_other_traits!(Typed); + +#[derive(Debug, Clone, Eq)] +pub struct Normalized(pub(crate) SubExpr, pub(crate) Type); +derive_other_traits!(Normalized); -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Type(pub(crate) TypeInternal); -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum TypeInternal { Expr(Box), Untyped, } - -#[derive(Debug, Clone)] -pub struct Normalized(pub(crate) SubExpr, pub(crate) Type); - -impl PartialEq for Parsed { - fn eq(&self, other: &Self) -> bool { - self.0 == other.0 - } -} -impl std::fmt::Display for Parsed { - fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { - self.0.fmt(f) - } -} -- cgit v1.2.3