Case
XML source file can contain element <Element/> or <Element>text</Element> or not contain the span.
The type for it should be defined as:
#[derive(Debug, PartialEq, XmlRead, XmlWrite)]
#[xml(tag = "Parent")]
pub struct Parent<'a> {
#[xml(child = "Element")]
pub element: Option<Element<'a>>,
}
#[derive(Debug, PartialEq, XmlRead, XmlWrite)]
#[xml(tag = "Element")]
pub struct Element<'a> {
#[xml(text)]
pub content: Option<Cow<'a, str>>,
}
Expected behavior
<Element>text<Element/> => text is loaded into the instance
<Element/> => parent->element->content should be None
- not specified =>
parent->element should be None
Or in case of defining the Element with flatten_text the case 2 and 3 can either have the same outcome or parent-element->text should be an empty/default value (empty string) for case 2.
Actual behavior
Case 1 and 3 work as expected. With case 2, however, I'm getting the following error:
UnexpectedToken { token: "ElementEnd { end: Empty, span: StrSpan(\"/>\" 2005..2007) }" }'
Same thing when using flatten_text.
Related issue
Having
#[derive(Debug, PartialEq, XmlRead, XmlWrite)]
#[xml(tag = "Element")]
pub struct Element<'a> {
#[xml(text)]
pub content: Option<Cow<'a, str>>,
}
Has error
| #[derive(Debug, PartialEq, XmlRead, XmlWrite)]
| ^^^^^^^^ expected `str`, found reference
|
= note: expected reference `&str`
found reference `&&std::option::Option<std::borrow::Cow<'_, str>>`
Although it says that Option<Cow<str>> should be supported. I can implement the XmlWrite myself, but that results in the issue mentioned above.
Case
XML source file can contain element
<Element/>or<Element>text</Element>or not contain the span.The type for it should be defined as:
Expected behavior
<Element>text<Element/>=>textis loaded into the instance<Element/>=>parent->element->contentshould beNoneparent->elementshould beNoneOr in case of defining the
Elementwithflatten_textthe case 2 and 3 can either have the same outcome orparent-element->textshould be an empty/default value (empty string) for case 2.Actual behavior
Case 1 and 3 work as expected. With case 2, however, I'm getting the following error:
Same thing when using
flatten_text.Related issue
Having
Has error
Although it says that
Option<Cow<str>>should be supported. I can implement theXmlWritemyself, but that results in the issue mentioned above.