mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +01:00
Move code into separate visit function
This commit is contained in:
parent
e8880a1a57
commit
9ba2e75ac1
@ -293,6 +293,22 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
|
|||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
|
fn visit<'de, T, V>(
|
||||||
|
val: T,
|
||||||
|
name: &'static str,
|
||||||
|
fields: &'static [&'static str],
|
||||||
|
visitor: V
|
||||||
|
) -> Result<V::Value, ShellError>
|
||||||
|
where
|
||||||
|
T: serde::Serialize,
|
||||||
|
V: Visitor<'de>,
|
||||||
|
{
|
||||||
|
let json = serde_json::to_string(&val)?;
|
||||||
|
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);
|
||||||
|
}
|
||||||
trace!(
|
trace!(
|
||||||
"deserializing struct {:?} {:?} (stack={:?})",
|
"deserializing struct {:?} {:?} (stack={:?})",
|
||||||
name,
|
name,
|
||||||
@ -315,11 +331,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
|
|||||||
} => block,
|
} => block,
|
||||||
other => return Err(ShellError::type_error("Block", other.tagged_type_name())),
|
other => return Err(ShellError::type_error("Block", other.tagged_type_name())),
|
||||||
};
|
};
|
||||||
let json = serde_json::to_string(&block)?;
|
return visit(block, name, fields, visitor);
|
||||||
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>();
|
||||||
|
Loading…
Reference in New Issue
Block a user