mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 05:52:19 +00:00
xml: Replace Unit with ()
This commit is contained in:
@@ -117,7 +117,7 @@ impl Variant {
|
||||
quote! {
|
||||
#variant_name => {
|
||||
// Make sure that content is still consumed
|
||||
::rustical_xml::Unit::deserialize(reader, start, empty)?;
|
||||
<() as ::rustical_xml::XmlDeserialize>::deserialize(reader, start, empty)?;
|
||||
Ok(Self::#ident)
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ impl Variant {
|
||||
quote! {
|
||||
_ => {
|
||||
// Make sure that content is still consumed
|
||||
::rustical_xml::Unit::deserialize(reader, start, empty)?;
|
||||
<() as ::rustical_xml::XmlDeserialize>::deserialize(reader, start, empty)?;
|
||||
Ok(Self::#ident)
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ impl Variant {
|
||||
Fields::Unit => {
|
||||
quote! {
|
||||
// Make sure that content is still consumed
|
||||
if let Ok(_) = ::rustical_xml::Unit::deserialize(reader, start, empty) {
|
||||
if let Ok(_) = <() as ::rustical_xml::XmlDeserialize>::deserialize(reader, start, empty) {
|
||||
return Ok(Self::#ident);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,32 +12,19 @@ pub use de::XmlRootTag;
|
||||
pub use se::XmlSerialize;
|
||||
pub use value::Value;
|
||||
|
||||
// impl<T: XmlDeserialize> XmlDeserialize for Option<T> {
|
||||
// fn deserialize<R: BufRead>(
|
||||
// reader: &mut quick_xml::NsReader<R>,
|
||||
// start: &BytesStart,
|
||||
// empty: bool,
|
||||
// ) -> Result<Self, XmlDeError> {
|
||||
// Ok(Some(T::deserialize(reader, start, empty)?))
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Unit;
|
||||
|
||||
impl XmlDeserialize for Unit {
|
||||
impl XmlDeserialize for () {
|
||||
fn deserialize<R: BufRead>(
|
||||
reader: &mut quick_xml::NsReader<R>,
|
||||
start: &BytesStart,
|
||||
empty: bool,
|
||||
) -> Result<Self, XmlDeError> {
|
||||
if empty {
|
||||
return Ok(Unit);
|
||||
return Ok(());
|
||||
}
|
||||
let mut buf = Vec::new();
|
||||
loop {
|
||||
match reader.read_event_into(&mut buf)? {
|
||||
Event::End(e) if e.name() == start.name() => return Ok(Unit),
|
||||
Event::End(e) if e.name() == start.name() => return Ok(()),
|
||||
Event::Eof => return Err(XmlDeError::Eof),
|
||||
_ => {}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use rustical_xml::{de::XmlDocument, Unit, XmlDeserialize, XmlRootTag};
|
||||
use rustical_xml::{de::XmlDocument, XmlDeserialize, XmlRootTag};
|
||||
|
||||
#[test]
|
||||
fn test_struct_tagged_enum() {
|
||||
@@ -78,7 +78,7 @@ fn test_tagged_enum_complex() {
|
||||
|
||||
#[derive(Debug, XmlDeserialize, PartialEq)]
|
||||
struct Nice {
|
||||
nice: Unit,
|
||||
nice: (),
|
||||
}
|
||||
|
||||
let asd = Propfind::parse_str(
|
||||
@@ -94,7 +94,6 @@ fn test_tagged_enum_complex() {
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
dbg!(asd);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use rustical_xml::de::XmlDocument;
|
||||
use rustical_xml::XmlRootTag;
|
||||
use rustical_xml::{Unit, Unparsed, XmlDeserialize};
|
||||
use rustical_xml::{Unparsed, XmlDeserialize};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[test]
|
||||
@@ -155,11 +155,11 @@ fn test_struct_ns() {
|
||||
#[xml(root = b"document", ns_strict)]
|
||||
struct Document {
|
||||
#[xml(ns = b"hello")]
|
||||
child: Unit,
|
||||
child: (),
|
||||
}
|
||||
|
||||
let doc = Document::parse_str(r#"<document><child xmlns="hello" /></document>"#).unwrap();
|
||||
assert_eq!(doc, Document { child: Unit });
|
||||
assert_eq!(doc, Document { child: () });
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -168,7 +168,7 @@ fn test_struct_attr() {
|
||||
#[xml(root = b"document", ns_strict)]
|
||||
struct Document {
|
||||
#[xml(ns = b"hello")]
|
||||
child: Unit,
|
||||
child: (),
|
||||
#[xml(ty = "attr", default = "Default::default")]
|
||||
test: String,
|
||||
#[xml(ty = "attr")]
|
||||
@@ -182,7 +182,7 @@ fn test_struct_attr() {
|
||||
assert_eq!(
|
||||
doc,
|
||||
Document {
|
||||
child: Unit,
|
||||
child: (),
|
||||
test: "hello!".to_owned(),
|
||||
number: 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user