From cd4137cda19a617caff47c396c574eae29cc4e93 Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:53:32 +0100 Subject: [PATCH] xml: small changes --- crates/xml/derive/src/de/de_struct.rs | 17 ++++------------- crates/xml/src/de.rs | 1 + crates/xml/tests/de_enum.rs | 9 ++++----- crates/xml/tests/de_struct.rs | 2 +- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/crates/xml/derive/src/de/de_struct.rs b/crates/xml/derive/src/de/de_struct.rs index 87fbccf..822d87a 100644 --- a/crates/xml/derive/src/de/de_struct.rs +++ b/crates/xml/derive/src/de/de_struct.rs @@ -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) => { diff --git a/crates/xml/src/de.rs b/crates/xml/src/de.rs index e85c320..bc801f9 100644 --- a/crates/xml/src/de.rs +++ b/crates/xml/src/de.rs @@ -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; diff --git a/crates/xml/tests/de_enum.rs b/crates/xml/tests/de_enum.rs index 21d13fc..79f5569 100644 --- a/crates/xml/tests/de_enum.rs +++ b/crates/xml/tests/de_enum.rs @@ -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#" - + "#, @@ -35,7 +34,7 @@ fn test_struct_untagged_enum() { assert_eq!( doc, Propfind { - prop: Prop { prop: PropEnum::A } + prop: Prop { prop: PropEnum::B } } ); } diff --git a/crates/xml/tests/de_struct.rs b/crates/xml/tests/de_struct.rs index fde54c7..00f7547 100644 --- a/crates/xml/tests/de_struct.rs +++ b/crates/xml/tests/de_struct.rs @@ -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() {