summaryrefslogtreecommitdiff
path: root/dhall/src/api/static_type.rs
diff options
context:
space:
mode:
authorNadrieril2019-08-12 23:24:48 +0200
committerNadrieril2019-08-13 14:24:56 +0200
commit52f9ecfc4dac65d305fd920e8c7f748889a0804f (patch)
tree106a54c066d1a38e99a73644f0b8f20df280b7e7 /dhall/src/api/static_type.rs
parent7d17d39005531cb77d8eaf32ed7de8938c66f874 (diff)
Move api into its own crate
Diffstat (limited to 'dhall/src/api/static_type.rs')
-rw-r--r--dhall/src/api/static_type.rs93
1 files changed, 0 insertions, 93 deletions
diff --git a/dhall/src/api/static_type.rs b/dhall/src/api/static_type.rs
deleted file mode 100644
index 906bcef..0000000
--- a/dhall/src/api/static_type.rs
+++ /dev/null
@@ -1,93 +0,0 @@
-use dhall_syntax::{Builtin, Integer, Natural};
-
-use crate::api::Type;
-
-/// A Rust type that can be represented as a Dhall type.
-///
-/// A typical example is `Option<bool>`,
-/// represented by the dhall expression `Optional Bool`.
-///
-/// This trait can and should be automatically derived.
-///
-/// The representation needs to be independent of the value.
-/// For this reason, something like `HashMap<String, bool>` cannot implement
-/// [StaticType] because each different value would
-/// have a different Dhall record type.
-pub trait StaticType {
- fn static_type() -> Type;
-}
-
-macro_rules! derive_builtin {
- ($ty:ty, $builtin:ident) => {
- impl StaticType for $ty {
- fn static_type() -> Type {
- Type::make_builtin_type(Builtin::$builtin)
- }
- }
- };
-}
-
-derive_builtin!(bool, Bool);
-derive_builtin!(Natural, Natural);
-derive_builtin!(u64, Natural);
-derive_builtin!(Integer, Integer);
-derive_builtin!(String, Text);
-
-impl<A, B> StaticType for (A, B)
-where
- A: StaticType,
- B: StaticType,
-{
- fn static_type() -> Type {
- Type::make_record_type(
- vec![
- ("_1".to_owned(), A::static_type()),
- ("_2".to_owned(), B::static_type()),
- ]
- .into_iter(),
- )
- }
-}
-
-impl<T, E> StaticType for std::result::Result<T, E>
-where
- T: StaticType,
- E: StaticType,
-{
- fn static_type() -> Type {
- Type::make_union_type(
- vec![
- ("Ok".to_owned(), Some(T::static_type())),
- ("Err".to_owned(), Some(E::static_type())),
- ]
- .into_iter(),
- )
- }
-}
-
-impl<T> StaticType for Option<T>
-where
- T: StaticType,
-{
- fn static_type() -> Type {
- Type::make_optional_type(T::static_type())
- }
-}
-
-impl<T> StaticType for Vec<T>
-where
- T: StaticType,
-{
- fn static_type() -> Type {
- Type::make_list_type(T::static_type())
- }
-}
-
-impl<'a, T> StaticType for &'a T
-where
- T: StaticType,
-{
- fn static_type() -> Type {
- T::static_type()
- }
-}