diff options
author | Nadrieril | 2019-04-07 18:04:45 +0200 |
---|---|---|
committer | Nadrieril | 2019-04-07 18:04:45 +0200 |
commit | 21b1fda39e51d157dadbfbb2aeb0f542a9506fcf (patch) | |
tree | 09012b2d9294a58455b74e8bd0e041f7cb153a23 /dhall/src/traits.rs | |
parent | 727c5219c9af55df3e61fb372fa2fadecdd15b18 (diff) | |
parent | 4bebcd96b6e76b9b8ae7877af91d2ae571e617a9 (diff) |
Merge branch 'statemachine-api'
Diffstat (limited to 'dhall/src/traits.rs')
-rw-r--r-- | dhall/src/traits.rs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/dhall/src/traits.rs b/dhall/src/traits.rs new file mode 100644 index 0000000..64e07d9 --- /dev/null +++ b/dhall/src/traits.rs @@ -0,0 +1,77 @@ +use dhall_core::*; +use dhall_generator::*; + +#[derive(Debug, Clone)] +pub enum ConversionError {} + +pub trait StaticType { + fn get_type() -> DhallExpr; + // fn as_dhall(&self) -> DhallExpr; + // fn from_dhall(e: DhallExpr) -> Result<Self, DhallConversionError>; +} + +impl StaticType for bool { + fn get_type() -> DhallExpr { + dhall_expr!(Bool) + } +} + +impl StaticType for Natural { + fn get_type() -> DhallExpr { + dhall_expr!(Natural) + } +} + +impl StaticType for Integer { + fn get_type() -> DhallExpr { + dhall_expr!(Integer) + } +} + +impl StaticType for String { + fn get_type() -> DhallExpr { + dhall_expr!(Text) + } +} + +impl<A: StaticType, B: StaticType> StaticType for (A, B) { + fn get_type() -> DhallExpr { + let ta = A::get_type(); + let tb = B::get_type(); + dhall_expr!({ _1: ta, _2: tb }) + } +} + +impl<T: StaticType> StaticType for Option<T> { + fn get_type() -> DhallExpr { + let t = T::get_type(); + dhall_expr!(Optional t) + } +} + +impl<T: StaticType> StaticType for Vec<T> { + fn get_type() -> DhallExpr { + let t = T::get_type(); + dhall_expr!(List t) + } +} + +impl<'a, T: StaticType> StaticType for &'a T { + fn get_type() -> DhallExpr { + T::get_type() + } +} + +impl<T> StaticType for std::marker::PhantomData<T> { + fn get_type() -> DhallExpr { + dhall_expr!({}) + } +} + +impl<T: StaticType, E: StaticType> StaticType for Result<T, E> { + fn get_type() -> DhallExpr { + let tt = T::get_type(); + let te = E::get_type(); + dhall_expr!(< Ok: tt | Err: te>) + } +} |