summaryrefslogtreecommitdiff
path: root/dhall/src/phase/binary.rs
diff options
context:
space:
mode:
authorNadrieril2019-08-13 22:11:45 +0200
committerNadrieril2019-08-13 22:11:45 +0200
commit8d45d633dfa60e8d64c9e6e742de4e33496bf0fa (patch)
tree526c351bbdd6121cdde3cd56f721156d3b34e6de /dhall/src/phase/binary.rs
parent07956ccb1daf4a6819f64776f70b6f5f26869184 (diff)
Store Imports in their own node instead of in Embed
Diffstat (limited to '')
-rw-r--r--dhall/src/phase/binary.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs
index 3292617..b3a80aa 100644
--- a/dhall/src/phase/binary.rs
+++ b/dhall/src/phase/binary.rs
@@ -19,7 +19,6 @@ pub fn decode(data: &[u8]) -> Result<DecodedSubExpr, DecodeError> {
}
}
-//TODO: encode normalized expression too
pub fn encode(expr: &ParsedSubExpr) -> Result<Vec<u8>, EncodeError> {
serde_cbor::ser::to_vec(&Serialize::Expr(expr))
.map_err(|e| EncodeError::CBORError(e))
@@ -264,7 +263,7 @@ fn cbor_value_to_dhall(
// TODO
// Some(x) => {
// match cbor_value_to_dhall(&x)?.as_ref() {
- // Embed(import) => Some(Box::new(
+ // Import(import) => Some(Box::new(
// import.location_hashed.clone(),
// )),
// _ => Err(DecodeError::WrongFormatError(
@@ -340,7 +339,7 @@ fn cbor_value_to_dhall(
"import/type".to_owned(),
))?,
};
- Embed(Import {
+ Import(dhall_syntax::Import {
mode,
location_hashed: ImportHashed { hash, location },
})
@@ -573,7 +572,10 @@ where
.chain(once(expr(x)))
.chain(ls.iter().map(label)),
),
- Embed(import) => serialize_import(ser, import),
+ Import(import) => serialize_import(ser, import),
+ Embed(_) => unimplemented!(
+ "An expression with resolved imports cannot be binary-encoded"
+ ),
}
}
@@ -631,12 +633,14 @@ where
ImportLocation::Remote(url) => {
match &url.headers {
None => ser_seq.serialize_element(&Null)?,
- Some(location_hashed) => ser_seq.serialize_element(
- &self::Serialize::Expr(&rc(ExprF::Embed(Import {
- mode: ImportMode::Code,
- location_hashed: location_hashed.as_ref().clone(),
- }))),
- )?,
+ Some(location_hashed) => {
+ ser_seq.serialize_element(&self::Serialize::Expr(&rc(
+ ExprF::Import(dhall_syntax::Import {
+ mode: ImportMode::Code,
+ location_hashed: location_hashed.as_ref().clone(),
+ }),
+ )))?
+ }
};
ser_seq.serialize_element(&url.authority)?;
for p in &url.path {