diff options
Diffstat (limited to 'dhall/src/traits/static_type.rs')
-rw-r--r-- | dhall/src/traits/static_type.rs | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/dhall/src/traits/static_type.rs b/dhall/src/traits/static_type.rs index 6b0f5c5..35d91e1 100644 --- a/dhall/src/traits/static_type.rs +++ b/dhall/src/traits/static_type.rs @@ -3,7 +3,7 @@ use dhall_core::*; use dhall_generator::*; pub trait StaticType { - fn get_static_type() -> Type; + fn get_static_type() -> Type<'static>; } /// Trait for rust types that can be represented in dhall in @@ -12,79 +12,80 @@ pub trait StaticType { /// is `HashMap<Text, bool>` because dhall cannot represent records with a /// variable number of fields. pub trait SimpleStaticType { - fn get_simple_static_type() -> SimpleType; + fn get_simple_static_type<'a>() -> SimpleType<'a>; } -fn mktype(x: SubExpr<X, X>) -> SimpleType { - SimpleType(x) +fn mktype<'a>(x: SubExpr<X, X>) -> SimpleType<'a> { + SimpleType(x, std::marker::PhantomData) } impl<T: SimpleStaticType> StaticType for T { - fn get_static_type() -> Type { + fn get_static_type() -> Type<'static> { crate::expr::Normalized( T::get_simple_static_type().into(), Some(Type::const_type()), + std::marker::PhantomData, ) .into_type() } } -impl StaticType for SimpleType { - fn get_static_type() -> Type { +impl<'a> StaticType for SimpleType<'a> { + fn get_static_type() -> Type<'static> { Type::const_type() } } impl SimpleStaticType for bool { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { mktype(dhall_expr!(Bool)) } } impl SimpleStaticType for Natural { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { mktype(dhall_expr!(Natural)) } } impl SimpleStaticType for u32 { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { mktype(dhall_expr!(Natural)) } } impl SimpleStaticType for u64 { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { mktype(dhall_expr!(Natural)) } } impl SimpleStaticType for Integer { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { mktype(dhall_expr!(Integer)) } } impl SimpleStaticType for i32 { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { mktype(dhall_expr!(Integer)) } } impl SimpleStaticType for i64 { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { mktype(dhall_expr!(Integer)) } } impl SimpleStaticType for String { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { mktype(dhall_expr!(Text)) } } impl<A: SimpleStaticType, B: SimpleStaticType> SimpleStaticType for (A, B) { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { let ta: SubExpr<_, _> = A::get_simple_static_type().into(); let tb: SubExpr<_, _> = B::get_simple_static_type().into(); mktype(dhall_expr!({ _1: ta, _2: tb })) @@ -92,27 +93,27 @@ impl<A: SimpleStaticType, B: SimpleStaticType> SimpleStaticType for (A, B) { } impl<T: SimpleStaticType> SimpleStaticType for Option<T> { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { let t: SubExpr<_, _> = T::get_simple_static_type().into(); mktype(dhall_expr!(Optional t)) } } impl<T: SimpleStaticType> SimpleStaticType for Vec<T> { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { let t: SubExpr<_, _> = T::get_simple_static_type().into(); mktype(dhall_expr!(List t)) } } -impl<'a, T: SimpleStaticType> SimpleStaticType for &'a T { - fn get_simple_static_type() -> SimpleType { +impl<'b, T: SimpleStaticType> SimpleStaticType for &'b T { + fn get_simple_static_type<'a>() -> SimpleType<'a> { T::get_simple_static_type() } } impl<T> SimpleStaticType for std::marker::PhantomData<T> { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { mktype(dhall_expr!({})) } } @@ -120,7 +121,7 @@ impl<T> SimpleStaticType for std::marker::PhantomData<T> { impl<T: SimpleStaticType, E: SimpleStaticType> SimpleStaticType for std::result::Result<T, E> { - fn get_simple_static_type() -> SimpleType { + fn get_simple_static_type<'a>() -> SimpleType<'a> { let tt: SubExpr<_, _> = T::get_simple_static_type().into(); let te: SubExpr<_, _> = E::get_simple_static_type().into(); mktype(dhall_expr!(< Ok: tt | Err: te>)) |