From 5b91eaa9d6b70a2ac72fe19f2d21871c8d94b017 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 6 May 2019 23:21:19 +0200 Subject: Move api-related modules into an api module --- dhall/src/api/traits/dynamic_type.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 dhall/src/api/traits/dynamic_type.rs (limited to 'dhall/src/api/traits/dynamic_type.rs') diff --git a/dhall/src/api/traits/dynamic_type.rs b/dhall/src/api/traits/dynamic_type.rs new file mode 100644 index 0000000..7763a28 --- /dev/null +++ b/dhall/src/api/traits/dynamic_type.rs @@ -0,0 +1,32 @@ +use crate::error::TypeError; +use crate::phase::{Normalized, Type, Typed}; +use crate::traits::StaticType; +use std::borrow::Cow; + +pub trait DynamicType { + fn get_type<'a>(&'a self) -> Result, TypeError>; +} + +impl DynamicType for T { + fn get_type<'a>(&'a self) -> Result, TypeError> { + Ok(Cow::Owned(T::get_static_type())) + } +} + +impl DynamicType for Type { + fn get_type(&self) -> Result, TypeError> { + self.get_type() + } +} + +impl DynamicType for Normalized { + fn get_type(&self) -> Result, TypeError> { + self.0.get_type() + } +} + +impl DynamicType for Typed { + fn get_type(&self) -> Result, TypeError> { + self.get_type() + } +} -- cgit v1.2.3