Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions instant-xml-macros/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ fn deserialize_struct(
let mut declare_values = TokenStream::new();
let mut return_val = TokenStream::new();
let mut direct = TokenStream::new();
let mut after_loop = TokenStream::new();

let mut borrowed = BTreeSet::new();
for (index, field) in fields.named.iter().enumerate() {
Expand Down Expand Up @@ -264,7 +263,6 @@ fn deserialize_struct(
field_meta,
&input.ident,
&container_meta,
&mut after_loop,
);

if let Err(err) = result {
Expand Down Expand Up @@ -363,7 +361,6 @@ fn deserialize_struct(
node => return Err(Error::UnexpectedNode(format!("{:?} in {}", node, #ident_str))),
}
}
#after_loop

*into = Some(Self { #return_val });
Ok(())
Expand Down Expand Up @@ -404,7 +401,6 @@ fn deserialize_inline_struct(
let mut declare_values = TokenStream::new();
let mut return_val = TokenStream::new();
let mut direct = TokenStream::new();
let mut after_loop = TokenStream::new();

let mut borrowed = BTreeSet::new();
let mut matches = TokenStream::new();
Expand Down Expand Up @@ -437,7 +433,6 @@ fn deserialize_inline_struct(
field_meta,
&input.ident,
&meta,
&mut after_loop,
);

let data = match result {
Expand Down Expand Up @@ -553,7 +548,6 @@ fn named_field<'a>(
mut field_meta: FieldMeta,
type_name: &Ident,
container_meta: &ContainerMeta,
after_loop: &mut TokenStream,
) -> Result<FieldData<'a>, syn::Error> {
let field_name = field.ident.as_ref().unwrap();
let field_tag = field_meta.tag;
Expand Down Expand Up @@ -650,16 +644,6 @@ fn named_field<'a>(
<#no_lifetime_type as FromXml>::deserialize(&mut #val_name, #field_str, &mut nested)?;
}
));
// We can only enter this FromXml impl if the caller found the opening
// tag, so if we don't see the text node before the closing tag that is
// implied by terminating the loop, we need to populate the
// direct field with the implied empty text node.
after_loop.extend(quote!(
if !seen_direct {
let mut nested = deserializer.for_node(Node::Text("".into()));
<#no_lifetime_type as FromXml>::deserialize(&mut #val_name, #field_str, &mut nested)?;
}
));
} else {
tokens.r#match.extend(quote!(
__Elements::#enum_name => match <#no_lifetime_type as FromXml>::KIND {
Expand Down Expand Up @@ -700,9 +684,24 @@ fn named_field<'a>(
}
};

return_val.extend(quote!(
#field_name: #val_name.try_done(#field_str)?,
));
if !field_meta.direct {
return_val.extend(quote!(
#field_name: #val_name.try_done(#field_str)?,
));
} else {
return_val.extend(quote!(
#field_name: match #val_name.try_done(#field_str) {
Ok(value) => value,
Err(Error::MissingValue(_)) => {
let mut acc = <#no_lifetime_type as FromXml>::Accumulator::default();
let mut nested = deserializer.for_node(Node::Text("".into()));
<#no_lifetime_type as FromXml>::deserialize(&mut acc, #field_str, &mut nested)?;
acc.try_done(#field_str)?
}
Err(e) => return Err(e),
}
));
}

Ok(FieldData {
field_name,
Expand Down
Loading