summaryrefslogtreecommitdiff
path: root/serde_dhall
diff options
context:
space:
mode:
authorNadrieril2019-08-16 19:16:40 +0200
committerNadrieril2019-08-16 19:16:40 +0200
commit45fb07f74f19919f742be6fe7793dc72d4022f26 (patch)
treefffab6fdb5b59e6e32eec60b3c4adfa5835e4778 /serde_dhall
parentfcc9afb3624883c4f99320c37678b7f9d338630d (diff)
Try to minimize untyped TypedThunks
Diffstat (limited to 'serde_dhall')
-rw-r--r--serde_dhall/src/lib.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs
index f400206..a277977 100644
--- a/serde_dhall/src/lib.rs
+++ b/serde_dhall/src/lib.rs
@@ -160,20 +160,21 @@ pub mod value {
self.0.to_type()
}
- pub(crate) fn from_dhall_value(v: DhallValue) -> Self {
- Value(Typed::from_value_untyped(v))
+ /// Assumes that the given value has type `Type`.
+ pub(crate) fn make_simple_type(v: DhallValue) -> Self {
+ Value(Typed::from_value_and_type(v, Type::const_type()))
}
pub(crate) fn make_builtin_type(b: Builtin) -> Self {
- Self::from_dhall_value(DhallValue::from_builtin(b))
+ Self::make_simple_type(DhallValue::from_builtin(b))
}
pub(crate) fn make_optional_type(t: Value) -> Self {
- Self::from_dhall_value(
+ Self::make_simple_type(
DhallValue::from_builtin(Builtin::Optional)
.app_thunk(t.to_thunk()),
)
}
pub(crate) fn make_list_type(t: Value) -> Self {
- Self::from_dhall_value(
+ Self::make_simple_type(
DhallValue::from_builtin(Builtin::List).app_thunk(t.to_thunk()),
)
}
@@ -182,9 +183,9 @@ pub mod value {
pub fn make_record_type(
kts: impl Iterator<Item = (String, Value)>,
) -> Self {
- Self::from_dhall_value(DhallValue::RecordType(
+ Self::make_simple_type(DhallValue::RecordType(
kts.map(|(k, t)| {
- (k.into(), TypedThunk::from_thunk(t.to_thunk()))
+ (k.into(), TypedThunk::from_thunk_simple_type(t.to_thunk()))
})
.collect(),
))
@@ -193,9 +194,14 @@ pub mod value {
pub fn make_union_type(
kts: impl Iterator<Item = (String, Option<Value>)>,
) -> Self {
- Self::from_dhall_value(DhallValue::UnionType(
+ Self::make_simple_type(DhallValue::UnionType(
kts.map(|(k, t)| {
- (k.into(), t.map(|t| TypedThunk::from_thunk(t.to_thunk())))
+ (
+ k.into(),
+ t.map(|t| {
+ TypedThunk::from_thunk_simple_type(t.to_thunk())
+ }),
+ )
})
.collect(),
))