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

View File

@@ -1,5 +1,6 @@
use std::io::BufRead; use std::io::BufRead;
pub use xml_derive::XmlDeserialize; pub use xml_derive::XmlDeserialize;
pub use xml_derive::XmlRoot;
use quick_xml::events::{BytesStart, Event}; use quick_xml::events::{BytesStart, Event};
use thiserror::Error; 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 std::io::BufRead;
use xml_derive::XmlDeserialize;
#[test] #[test]
fn test_struct_untagged_enum() { fn test_struct_untagged_enum() {
#[derive(Debug, XmlDeserialize, PartialEq)] #[derive(Debug, XmlDeserialize, XmlRoot, PartialEq)]
#[xml(root = b"propfind")] #[xml(root = b"propfind")]
struct Propfind { struct Propfind {
prop: Prop, prop: Prop,
@@ -26,7 +25,7 @@ fn test_struct_untagged_enum() {
r#" r#"
<propfind> <propfind>
<prop> <prop>
<A/> <b/>
</prop> </prop>
</propfind> </propfind>
"#, "#,
@@ -35,7 +34,7 @@ fn test_struct_untagged_enum() {
assert_eq!( assert_eq!(
doc, doc,
Propfind { 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::de::XmlRootParseStr;
use rustical_xml::XmlRoot;
use rustical_xml::{Unit, Unparsed, XmlDeserialize}; use rustical_xml::{Unit, Unparsed, XmlDeserialize};
use std::collections::HashSet; use std::collections::HashSet;
use std::io::BufRead; use std::io::BufRead;
use xml_derive::XmlRoot;
#[test] #[test]
fn test_struct_text_field() { fn test_struct_text_field() {