From e8880a1a5727ed1c06bc30704626a6084b5fb2ad Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 2 Sep 2019 22:30:51 +0200 Subject: [PATCH] Deserialize Block using serde --- src/object/types.rs | 13 ------------- src/parser/deserializer.rs | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/object/types.rs b/src/object/types.rs index 7965c76023..ece1ba3bde 100644 --- a/src/object/types.rs +++ b/src/object/types.rs @@ -1,4 +1,3 @@ -use crate::object::base as value; use crate::prelude::*; use log::trace; @@ -106,15 +105,3 @@ impl ExtractType for String { } } } - -impl ExtractType for value::Block { - fn extract(value: &Tagged) -> Result { - match value { - Tagged { - item: Value::Block(block), - .. - } => Ok(block.clone()), - other => Err(ShellError::type_error("Block", other.tagged_type_name())), - } - } -} diff --git a/src/parser/deserializer.rs b/src/parser/deserializer.rs index a2ec8a96c6..ea507128ef 100644 --- a/src/parser/deserializer.rs +++ b/src/parser/deserializer.rs @@ -306,6 +306,22 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> { } let value = self.pop(); + + if name == "Block" { + let block = match value.val { + Tagged { + item: Value::Block(block), + .. + } => block, + other => return Err(ShellError::type_error("Block", other.tagged_type_name())), + }; + let json = serde_json::to_string(&block)?; + let json_cursor = std::io::Cursor::new(json.into_bytes()); + let mut json_de = serde_json::Deserializer::from_reader(json_cursor); + let r = json_de.deserialize_struct(name, fields, visitor)?; + return Ok(r); + } + let name = std::any::type_name::(); trace!("Extracting {:?} for {:?}", value.val, name); V::Value::extract(&value.val)