diff --git a/instant-xml-macros/src/de.rs b/instant-xml-macros/src/de.rs index 100aeca..d9f2e2b 100644 --- a/instant-xml-macros/src/de.rs +++ b/instant-xml-macros/src/de.rs @@ -361,7 +361,7 @@ fn named_field( } else { tokens.r#match.extend(quote!( __Attributes::#enum_name => { - let mut nested = deserializer.for_attr(attr); + let mut nested = deserializer.for_node(Node::AttributeValue(attr.value)); let new = <#no_lifetime_type>::deserialize(&mut nested, &mut #enum_name)?; }, )); @@ -453,14 +453,15 @@ fn unnamed_field( let #name = match node { Node::Open(data) => { + let mut nested = deserializer.nested(data); let mut value: Option<#no_lifetime_type> = None; - <#no_lifetime_type>::deserialize(deserializer, &mut value)?; + <#no_lifetime_type>::deserialize(&mut nested, &mut value)?; value } Node::Text(data) => { - deserializer.push_front(Node::Text(data)); + let mut nested = deserializer.for_node(Node::Text(data)); let mut value: Option<#no_lifetime_type> = None; - <#no_lifetime_type>::deserialize(deserializer, &mut value)?; + <#no_lifetime_type>::deserialize(&mut nested, &mut value)?; value } node => return Err(Error::UnexpectedNode(format!("{:?}", node))), diff --git a/instant-xml/src/de.rs b/instant-xml/src/de.rs index 53d27fd..ca53ce9 100644 --- a/instant-xml/src/de.rs +++ b/instant-xml/src/de.rs @@ -59,23 +59,6 @@ impl<'cx, 'xml> Deserializer<'cx, 'xml> { Deserializer::new(element, self.context) } - pub fn for_attr<'a>(&'a mut self, attr: Attribute<'xml>) -> Deserializer<'a, 'xml> - where - 'cx: 'a, - { - self.context - .records - .push_front(Node::AttributeValue(attr.value)); - - Deserializer { - local: self.local, - prefix: self.prefix, - level: self.level, - done: self.done, - context: self.context, - } - } - pub fn ignore(&mut self) -> Result<(), Error> { loop { match self.next() { @@ -90,8 +73,18 @@ impl<'cx, 'xml> Deserializer<'cx, 'xml> { } } - pub fn push_front(&mut self, node: Node<'xml>) { + pub fn for_node<'a>(&'a mut self, node: Node<'xml>) -> Deserializer<'a, 'xml> + where + 'cx: 'a, + { self.context.records.push_front(node); + Deserializer { + local: self.local, + prefix: self.prefix, + level: self.level, + done: self.done, + context: self.context, + } } #[inline]