mirror of
https://github.com/nushell/nushell.git
synced 2025-01-03 13:00:08 +01:00
Deserialize Block using serde
This commit is contained in:
parent
9b3a561e83
commit
e8880a1a57
@ -1,4 +1,3 @@
|
|||||||
use crate::object::base as value;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
@ -106,15 +105,3 @@ impl ExtractType for String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtractType for value::Block {
|
|
||||||
fn extract(value: &Tagged<Value>) -> Result<value::Block, ShellError> {
|
|
||||||
match value {
|
|
||||||
Tagged {
|
|
||||||
item: Value::Block(block),
|
|
||||||
..
|
|
||||||
} => Ok(block.clone()),
|
|
||||||
other => Err(ShellError::type_error("Block", other.tagged_type_name())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -306,6 +306,22 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let value = self.pop();
|
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::<V::Value>();
|
let name = std::any::type_name::<V::Value>();
|
||||||
trace!("Extracting {:?} for {:?}", value.val, name);
|
trace!("Extracting {:?} for {:?}", value.val, name);
|
||||||
V::Value::extract(&value.val)
|
V::Value::extract(&value.val)
|
||||||
|
Loading…
Reference in New Issue
Block a user