xml: small changes

This commit is contained in:
Lennart
2024-12-22 12:53:32 +01:00
parent 043ce8bcd0
commit cd4137cda1
4 changed files with 10 additions and 19 deletions

View File

@@ -7,18 +7,9 @@ use syn::{DataStruct, DeriveInput};
fn invalid_field_branch(allow: bool) -> proc_macro2::TokenStream {
if allow {
quote! {
_ => {
// ignore because of allow_invalid flag
}
}
quote! {}
} else {
quote! {
_ => {
// invalid field name
return Err(XmlDeError::InvalidFieldName)
}
}
quote! { return Err(XmlDeError::InvalidFieldName) }
}
}
@@ -114,7 +105,7 @@ impl NamedStruct {
let attr = attr?;
match attr.key.as_ref() {
#(#attr_field_branches)*
#invalid_field_branch
_ => { #invalid_field_branch }
}
}
@@ -133,7 +124,7 @@ impl NamedStruct {
match (ns, name.as_ref()) {
#(#named_field_branches)*
#(#untagged_field_branches)*
#invalid_field_branch
_ => { #invalid_field_branch }
}
}
Event::Text(bytes_text) => {

View File

@@ -1,5 +1,6 @@
use std::io::BufRead;
pub use xml_derive::XmlDeserialize;
pub use xml_derive::XmlRoot;
use quick_xml::events::{BytesStart, Event};
use thiserror::Error;

View File

@@ -1,10 +1,9 @@
use rustical_xml::XmlRoot;
use rustical_xml::{de::XmlRootParseStr, XmlDeserialize, XmlRoot};
use std::io::BufRead;
use xml_derive::XmlDeserialize;
#[test]
fn test_struct_untagged_enum() {
#[derive(Debug, XmlDeserialize, PartialEq)]
#[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
#[xml(root = b"propfind")]
struct Propfind {
prop: Prop,
@@ -26,7 +25,7 @@ fn test_struct_untagged_enum() {
r#"
<propfind>
<prop>
<A/>
<b/>
</prop>
</propfind>
"#,
@@ -35,7 +34,7 @@ fn test_struct_untagged_enum() {
assert_eq!(
doc,
Propfind {
prop: Prop { prop: PropEnum::A }
prop: Prop { prop: PropEnum::B }
}
);
}

View File

@@ -1,8 +1,8 @@
use rustical_xml::de::XmlRootParseStr;
use rustical_xml::XmlRoot;
use rustical_xml::{Unit, Unparsed, XmlDeserialize};
use std::collections::HashSet;
use std::io::BufRead;
use xml_derive::XmlRoot;
#[test]
fn test_struct_text_field() {