2019-08-02 19:15:07 +00:00
|
|
|
use crate::prelude::*;
|
|
|
|
use log::trace;
|
2019-09-01 23:02:23 +00:00
|
|
|
use serde::de;
|
2019-09-03 00:10:48 +00:00
|
|
|
use std::path::PathBuf;
|
2019-08-02 19:15:07 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct DeserializerItem<'de> {
|
2019-09-02 00:43:07 +00:00
|
|
|
key_struct_field: Option<(String, &'de str)>,
|
2019-08-09 04:51:21 +00:00
|
|
|
val: Tagged<Value>,
|
2019-08-02 19:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ConfigDeserializer<'de> {
|
2019-08-17 03:53:39 +00:00
|
|
|
call: CallInfo,
|
2019-08-02 19:15:07 +00:00
|
|
|
stack: Vec<DeserializerItem<'de>>,
|
|
|
|
saw_root: bool,
|
|
|
|
position: usize,
|
|
|
|
}
|
|
|
|
|
2019-08-29 12:16:11 +00:00
|
|
|
impl<'de> ConfigDeserializer<'de> {
|
2019-08-17 03:53:39 +00:00
|
|
|
pub fn from_call_info(call: CallInfo) -> ConfigDeserializer<'de> {
|
2019-08-02 19:15:07 +00:00
|
|
|
ConfigDeserializer {
|
2019-08-17 03:53:39 +00:00
|
|
|
call,
|
2019-08-02 19:15:07 +00:00
|
|
|
stack: vec![],
|
|
|
|
saw_root: false,
|
|
|
|
position: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 01:25:34 +00:00
|
|
|
pub fn push_val(&mut self, val: Tagged<Value>) {
|
|
|
|
self.stack.push(DeserializerItem {
|
|
|
|
key_struct_field: None,
|
|
|
|
val,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-02 19:15:07 +00:00
|
|
|
pub fn push(&mut self, name: &'static str) -> Result<(), ShellError> {
|
2019-08-09 04:51:21 +00:00
|
|
|
let value: Option<Tagged<Value>> = if name == "rest" {
|
2019-08-17 03:53:39 +00:00
|
|
|
let positional = self.call.args.slice_from(self.position);
|
2019-08-02 19:15:07 +00:00
|
|
|
self.position += positional.len();
|
2019-09-05 16:23:42 +00:00
|
|
|
Some(Value::Table(positional).tagged_unknown()) // TODO: correct span
|
2019-08-02 19:15:07 +00:00
|
|
|
} else {
|
2019-08-17 03:53:39 +00:00
|
|
|
if self.call.args.has(name) {
|
|
|
|
self.call.args.get(name).map(|x| x.clone())
|
2019-08-02 19:15:07 +00:00
|
|
|
} else {
|
|
|
|
let position = self.position;
|
|
|
|
self.position += 1;
|
2019-08-17 03:53:39 +00:00
|
|
|
self.call.args.nth(position).map(|x| x.clone())
|
2019-08-02 19:15:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
trace!("pushing {:?}", value);
|
|
|
|
|
|
|
|
self.stack.push(DeserializerItem {
|
2019-09-02 00:43:07 +00:00
|
|
|
key_struct_field: Some((name.to_string(), name)),
|
2019-08-09 04:51:21 +00:00
|
|
|
val: value.unwrap_or_else(|| {
|
2019-08-17 03:53:39 +00:00
|
|
|
Value::nothing().tagged(Tag::unknown_origin(self.call.name_span))
|
2019-08-09 04:51:21 +00:00
|
|
|
}),
|
2019-08-02 19:15:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-09-03 00:49:51 +00:00
|
|
|
|
2019-09-01 22:32:26 +00:00
|
|
|
pub fn top(&mut self) -> &DeserializerItem {
|
|
|
|
let value = self.stack.last();
|
|
|
|
trace!("inspecting top value :: {:?}", value);
|
|
|
|
value.expect("Can't get top elemant of an empty stack")
|
|
|
|
}
|
2019-08-02 19:15:07 +00:00
|
|
|
|
|
|
|
pub fn pop(&mut self) -> DeserializerItem {
|
|
|
|
let value = self.stack.pop();
|
|
|
|
trace!("popping value :: {:?}", value);
|
|
|
|
value.expect("Can't pop an empty stack")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
use de::Visitor;
|
|
|
|
|
|
|
|
impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
|
|
|
|
type Error = ShellError;
|
|
|
|
fn deserialize_any<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
2019-09-02 02:07:02 +00:00
|
|
|
unimplemented!("deserialize_any")
|
2019-08-02 19:15:07 +00:00
|
|
|
}
|
2019-09-01 23:02:23 +00:00
|
|
|
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
let value = self.pop();
|
|
|
|
trace!("Extracting {:?} for bool", value.val);
|
2019-08-02 19:15:07 +00:00
|
|
|
|
2019-09-01 23:02:23 +00:00
|
|
|
match &value.val {
|
|
|
|
Tagged {
|
|
|
|
item: Value::Primitive(Primitive::Boolean(b)),
|
|
|
|
..
|
|
|
|
} => visitor.visit_bool(*b),
|
|
|
|
Tagged {
|
|
|
|
item: Value::Primitive(Primitive::Nothing),
|
|
|
|
..
|
|
|
|
} => visitor.visit_bool(false),
|
|
|
|
other => Err(ShellError::type_error("Boolean", other.tagged_type_name())),
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 19:15:07 +00:00
|
|
|
fn deserialize_i8<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_i8")
|
|
|
|
}
|
|
|
|
fn deserialize_i16<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_i16")
|
|
|
|
}
|
|
|
|
fn deserialize_i32<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_i32")
|
|
|
|
}
|
|
|
|
fn deserialize_i64<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_i64")
|
|
|
|
}
|
|
|
|
fn deserialize_u8<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_u8")
|
|
|
|
}
|
|
|
|
fn deserialize_u16<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_u16")
|
|
|
|
}
|
|
|
|
fn deserialize_u32<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_u32")
|
|
|
|
}
|
|
|
|
fn deserialize_u64<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_u64")
|
|
|
|
}
|
|
|
|
fn deserialize_f32<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_f32")
|
|
|
|
}
|
|
|
|
fn deserialize_f64<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_f64")
|
|
|
|
}
|
|
|
|
fn deserialize_char<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_char")
|
|
|
|
}
|
|
|
|
fn deserialize_str<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_str")
|
|
|
|
}
|
|
|
|
fn deserialize_string<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_string")
|
|
|
|
}
|
|
|
|
fn deserialize_bytes<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_bytes")
|
|
|
|
}
|
|
|
|
fn deserialize_byte_buf<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_byte_buf")
|
|
|
|
}
|
2019-09-03 00:49:51 +00:00
|
|
|
|
2019-09-01 22:32:26 +00:00
|
|
|
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
let value = self.top();
|
|
|
|
let name = std::any::type_name::<V::Value>();
|
|
|
|
trace!("<Option> Extracting {:?} for Option<{}>", value, name);
|
|
|
|
match value.val.item() {
|
|
|
|
Value::Primitive(Primitive::Nothing) => visitor.visit_none(),
|
|
|
|
_ => visitor.visit_some(self),
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 19:15:07 +00:00
|
|
|
|
|
|
|
fn deserialize_unit<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_unit")
|
|
|
|
}
|
|
|
|
fn deserialize_unit_struct<V>(
|
|
|
|
self,
|
|
|
|
_name: &'static str,
|
|
|
|
_visitor: V,
|
|
|
|
) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_unit_struct")
|
|
|
|
}
|
|
|
|
fn deserialize_newtype_struct<V>(
|
|
|
|
self,
|
|
|
|
_name: &'static str,
|
|
|
|
_visitor: V,
|
|
|
|
) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_newtype_struct")
|
|
|
|
}
|
2019-09-02 01:25:34 +00:00
|
|
|
fn deserialize_seq<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
let value = self.pop();
|
|
|
|
trace!("<Vec> Extracting {:?} for vec", value.val);
|
2019-08-02 19:15:07 +00:00
|
|
|
|
2019-09-02 01:25:34 +00:00
|
|
|
match value.val.into_parts() {
|
2019-09-05 16:23:42 +00:00
|
|
|
(Value::Table(items), _) => {
|
2019-09-02 01:25:34 +00:00
|
|
|
let de = SeqDeserializer::new(&mut self, items.into_iter());
|
|
|
|
visitor.visit_seq(de)
|
|
|
|
}
|
2019-09-05 16:23:42 +00:00
|
|
|
(other, tag) => Err(ShellError::type_error("Vec", other.type_name().tagged(tag))),
|
2019-09-02 01:25:34 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-02 01:37:01 +00:00
|
|
|
fn deserialize_tuple<V>(mut self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
|
2019-08-02 19:15:07 +00:00
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
2019-09-02 01:37:01 +00:00
|
|
|
let value = self.pop();
|
2019-09-05 16:23:42 +00:00
|
|
|
trace!(
|
|
|
|
"<Tuple> Extracting {:?} for tuple with {} elements",
|
|
|
|
value.val,
|
|
|
|
len
|
|
|
|
);
|
2019-09-02 01:37:01 +00:00
|
|
|
|
|
|
|
match value.val.into_parts() {
|
2019-09-05 16:23:42 +00:00
|
|
|
(Value::Table(items), _) => {
|
2019-09-02 01:37:01 +00:00
|
|
|
let de = SeqDeserializer::new(&mut self, items.into_iter());
|
|
|
|
visitor.visit_seq(de)
|
|
|
|
}
|
|
|
|
(other, tag) => Err(ShellError::type_error(
|
|
|
|
"Tuple",
|
|
|
|
other.type_name().tagged(tag),
|
|
|
|
)),
|
|
|
|
}
|
2019-08-02 19:15:07 +00:00
|
|
|
}
|
|
|
|
fn deserialize_tuple_struct<V>(
|
|
|
|
self,
|
|
|
|
_name: &'static str,
|
|
|
|
_len: usize,
|
|
|
|
_visitor: V,
|
|
|
|
) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_tuple_struct")
|
|
|
|
}
|
|
|
|
fn deserialize_map<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_map")
|
|
|
|
}
|
|
|
|
fn deserialize_struct<V>(
|
|
|
|
mut self,
|
|
|
|
name: &'static str,
|
|
|
|
fields: &'static [&'static str],
|
|
|
|
visitor: V,
|
|
|
|
) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
2019-09-02 21:21:29 +00:00
|
|
|
fn visit<'de, T, V>(
|
|
|
|
val: T,
|
|
|
|
name: &'static str,
|
|
|
|
fields: &'static [&'static str],
|
2019-09-05 16:23:42 +00:00
|
|
|
visitor: V,
|
2019-09-02 21:21:29 +00:00
|
|
|
) -> 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);
|
|
|
|
}
|
2019-08-02 19:15:07 +00:00
|
|
|
trace!(
|
|
|
|
"deserializing struct {:?} {:?} (stack={:?})",
|
|
|
|
name,
|
|
|
|
fields,
|
|
|
|
self.stack
|
|
|
|
);
|
|
|
|
|
2019-09-02 20:06:46 +00:00
|
|
|
if !self.saw_root {
|
2019-08-02 19:15:07 +00:00
|
|
|
self.saw_root = true;
|
2019-09-02 20:06:46 +00:00
|
|
|
return visitor.visit_seq(StructDeserializer::new(&mut self, fields));
|
2019-08-02 19:15:07 +00:00
|
|
|
}
|
2019-09-02 20:06:46 +00:00
|
|
|
|
|
|
|
let value = self.pop();
|
2019-09-02 20:30:51 +00:00
|
|
|
|
2019-09-02 21:23:34 +00:00
|
|
|
let type_name = std::any::type_name::<V::Value>();
|
|
|
|
let tagged_val_name = std::any::type_name::<Tagged<Value>>();
|
|
|
|
|
2019-09-09 11:02:25 +00:00
|
|
|
if type_name == tagged_val_name {
|
2019-09-02 21:23:34 +00:00
|
|
|
return visit::<Tagged<Value>, _>(value.val, name, fields, visitor);
|
|
|
|
}
|
|
|
|
|
2019-09-02 20:30:51 +00:00
|
|
|
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())),
|
|
|
|
};
|
2019-09-02 21:23:34 +00:00
|
|
|
return visit::<value::Block, _>(block, name, fields, visitor);
|
2019-09-02 20:30:51 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 21:23:34 +00:00
|
|
|
trace!("Extracting {:?} for {:?}", value.val, type_name);
|
2019-09-03 00:10:48 +00:00
|
|
|
|
|
|
|
let tag = value.val.tag();
|
|
|
|
match value.val {
|
|
|
|
Tagged {
|
|
|
|
item: Value::Primitive(Primitive::Boolean(b)),
|
|
|
|
..
|
|
|
|
} => visit::<Tagged<bool>, _>(b.tagged(tag), name, fields, visitor),
|
|
|
|
Tagged {
|
|
|
|
item: Value::Primitive(Primitive::Nothing),
|
|
|
|
..
|
|
|
|
} => visit::<Tagged<bool>, _>(false.tagged(tag), name, fields, visitor),
|
|
|
|
Tagged {
|
|
|
|
item: Value::Primitive(Primitive::Path(p)),
|
|
|
|
..
|
|
|
|
} => visit::<Tagged<PathBuf>, _>(p.clone().tagged(tag), name, fields, visitor),
|
|
|
|
Tagged {
|
|
|
|
item: Value::Primitive(Primitive::Int(int)),
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
let i: i64 = int.tagged(value.val.tag).coerce_into("converting to i64")?;
|
|
|
|
visit::<Tagged<i64>, _>(i.tagged(tag), name, fields, visitor)
|
2019-09-05 16:23:42 +00:00
|
|
|
}
|
2019-09-03 00:10:48 +00:00
|
|
|
Tagged {
|
|
|
|
item: Value::Primitive(Primitive::String(string)),
|
|
|
|
..
|
|
|
|
} => visit::<Tagged<String>, _>(string.tagged(tag), name, fields, visitor),
|
|
|
|
|
|
|
|
other => return Err(ShellError::type_error(name, other.tagged_type_name())),
|
|
|
|
}
|
2019-08-02 19:15:07 +00:00
|
|
|
}
|
|
|
|
fn deserialize_enum<V>(
|
|
|
|
self,
|
|
|
|
_name: &'static str,
|
|
|
|
_variants: &'static [&'static str],
|
|
|
|
_visitor: V,
|
|
|
|
) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_enum")
|
|
|
|
}
|
|
|
|
fn deserialize_identifier<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_identifier")
|
|
|
|
}
|
|
|
|
fn deserialize_ignored_any<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
|
where
|
|
|
|
V: Visitor<'de>,
|
|
|
|
{
|
|
|
|
unimplemented!("deserialize_ignored_any")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 16:23:42 +00:00
|
|
|
struct SeqDeserializer<'a, 'de: 'a, I: Iterator<Item = Tagged<Value>>> {
|
2019-09-02 01:25:34 +00:00
|
|
|
de: &'a mut ConfigDeserializer<'de>,
|
|
|
|
vals: I,
|
|
|
|
}
|
|
|
|
|
2019-09-05 16:23:42 +00:00
|
|
|
impl<'a, 'de: 'a, I: Iterator<Item = Tagged<Value>>> SeqDeserializer<'a, 'de, I> {
|
2019-09-02 01:25:34 +00:00
|
|
|
fn new(de: &'a mut ConfigDeserializer<'de>, vals: I) -> Self {
|
2019-09-05 16:23:42 +00:00
|
|
|
SeqDeserializer { de, vals }
|
2019-09-02 01:25:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 16:23:42 +00:00
|
|
|
impl<'a, 'de: 'a, I: Iterator<Item = Tagged<Value>>> de::SeqAccess<'de>
|
|
|
|
for SeqDeserializer<'a, 'de, I>
|
|
|
|
{
|
2019-09-02 01:25:34 +00:00
|
|
|
type Error = ShellError;
|
|
|
|
|
|
|
|
fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
|
|
|
where
|
|
|
|
T: de::DeserializeSeed<'de>,
|
|
|
|
{
|
|
|
|
let next = if let Some(next) = self.vals.next() {
|
|
|
|
next
|
|
|
|
} else {
|
|
|
|
return Ok(None);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.de.push_val(next);
|
|
|
|
seed.deserialize(&mut *self.de).map(Some)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn size_hint(&self) -> Option<usize> {
|
|
|
|
return self.vals.size_hint().1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-02 19:15:07 +00:00
|
|
|
struct StructDeserializer<'a, 'de: 'a> {
|
|
|
|
de: &'a mut ConfigDeserializer<'de>,
|
|
|
|
fields: &'static [&'static str],
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'de: 'a> StructDeserializer<'a, 'de> {
|
|
|
|
fn new(de: &'a mut ConfigDeserializer<'de>, fields: &'static [&'static str]) -> Self {
|
2019-09-05 16:23:42 +00:00
|
|
|
StructDeserializer { de, fields }
|
2019-08-02 19:15:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'de: 'a> de::SeqAccess<'de> for StructDeserializer<'a, 'de> {
|
|
|
|
type Error = ShellError;
|
|
|
|
|
|
|
|
fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
|
|
|
|
where
|
|
|
|
T: de::DeserializeSeed<'de>,
|
|
|
|
{
|
|
|
|
if self.fields.len() == 0 {
|
|
|
|
return Ok(None);
|
|
|
|
}
|
|
|
|
|
|
|
|
trace!("Processing {}", self.fields[0]);
|
|
|
|
|
|
|
|
self.de.push(self.fields[0])?;
|
|
|
|
self.fields = &self.fields[1..];
|
|
|
|
seed.deserialize(&mut *self.de).map(Some)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn size_hint(&self) -> Option<usize> {
|
|
|
|
return Some(self.fields.len());
|
|
|
|
}
|
|
|
|
}
|