summaryrefslogtreecommitdiff
path: root/dhall/src/api/traits/dynamic_type.rs
diff options
context:
space:
mode:
authorNadrieril2019-05-07 18:12:04 +0200
committerNadrieril2019-05-07 18:12:04 +0200
commit3da450aa3fae23214aa982643b9bc4dd0ea4eaa6 (patch)
tree02e00cd008d2e7dc899b9211379596fe792f41c8 /dhall/src/api/traits/dynamic_type.rs
parentd8a3e831fb67f86269c4baa99f9f0798a73a7247 (diff)
parent14dfeb8e7d2aa87a361a711a485243449426b144 (diff)
Merge branch 'reorganize'
Diffstat (limited to 'dhall/src/api/traits/dynamic_type.rs')
-rw-r--r--dhall/src/api/traits/dynamic_type.rs32
1 files changed, 32 insertions, 0 deletions
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<Cow<'a, Type>, TypeError>;
+}
+
+impl<T: StaticType> DynamicType for T {
+ fn get_type<'a>(&'a self) -> Result<Cow<'a, Type>, TypeError> {
+ Ok(Cow::Owned(T::get_static_type()))
+ }
+}
+
+impl DynamicType for Type {
+ fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> {
+ self.get_type()
+ }
+}
+
+impl DynamicType for Normalized {
+ fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> {
+ self.0.get_type()
+ }
+}
+
+impl DynamicType for Typed {
+ fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> {
+ self.get_type()
+ }
+}