mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 05:52:19 +00:00
xml: small changes
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user