Use serde to deserialize Tagged<Value>

This commit is contained in:
est31 2019-09-02 23:23:34 +02:00
parent 9ba2e75ac1
commit cc8872b4ee
2 changed files with 9 additions and 11 deletions

View File

@ -24,14 +24,6 @@ impl<T: ExtractType> ExtractType for Tagged<T> {
}
}
impl ExtractType for Value {
fn extract(value: &Tagged<Value>) -> Result<Value, ShellError> {
trace!("<Tagged> Extracting {:?} for Value", value);
Ok(value.item().clone())
}
}
impl ExtractType for bool {
fn extract(value: &Tagged<Value>) -> Result<bool, ShellError> {
trace!("Extracting {:?} for bool", value);

View File

@ -323,6 +323,13 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
let value = self.pop();
let type_name = std::any::type_name::<V::Value>();
let tagged_val_name = std::any::type_name::<Tagged<Value>>();
if name == tagged_val_name {
return visit::<Tagged<Value>, _>(value.val, name, fields, visitor);
}
if name == "Block" {
let block = match value.val {
Tagged {
@ -331,11 +338,10 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
} => block,
other => return Err(ShellError::type_error("Block", other.tagged_type_name())),
};
return visit(block, name, fields, visitor);
return visit::<value::Block, _>(block, name, fields, visitor);
}
let name = std::any::type_name::<V::Value>();
trace!("Extracting {:?} for {:?}", value.val, name);
trace!("Extracting {:?} for {:?}", value.val, type_name);
V::Value::extract(&value.val)
}
fn deserialize_enum<V>(