Running cargo test on the following code:
use yaserde_derive::YaDeserialize;
#[derive(Clone, Debug, Eq, PartialEq, YaDeserialize)]
#[yaserde(rename = "propfind", namespace = "DAV:")]
pub enum Propfind {
PropName { propname: PropName },
AllProp { allprop: AllProp },
}
// Just to shut yarserde up
impl Default for Propfind {
fn default() -> Propfind {
Propfind::AllProp { allprop: AllProp }
}
}
impl Propfind {
pub fn from_xml(s: &str) -> Result<Propfind, String> {
yaserde::de::from_str(s)
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq, YaDeserialize)]
pub struct AllProp;
#[derive(Clone, Debug, Default, Eq, PartialEq, YaDeserialize)]
pub struct PropName;
#[cfg(test)]
mod tests {
use super::*;
use indoc::indoc;
#[test]
fn allprop() {
let s = indoc! {r#"
<?xml version="1.0" encoding="utf-8" ?>
<propfind xmlns="DAV:">
<allprop/>
</propfind>
"#};
let pf = Propfind::from_xml(s).unwrap();
assert_eq!(pf, Propfind::AllProp { allprop: AllProp });
}
#[test]
fn propname() {
let s = indoc! {r#"
<?xml version="1.0" encoding="utf-8" ?>
<propfind xmlns="DAV:">
<propname/>
</propfind>
"#};
let pf = Propfind::from_xml(s).unwrap();
assert_eq!(pf, Propfind::PropName { propname: PropName });
}
}
with the following dependencies:
[dependencies]
yaserde = "0.9.1"
yaserde_derive = "0.9.1"
[dev-dependencies]
indoc = "2.0.4"
results in the propname test failing because the XML is deserialized as Propfind::AllProp { allprop: AllProp } instead of the expected Propfind::PropName variant.
How can I get the given XML snippets to deserialize the way I want?
Running
cargo teston the following code:with the following dependencies:
results in the
propnametest failing because the XML is deserialized asPropfind::AllProp { allprop: AllProp }instead of the expectedPropfind::PropNamevariant.How can I get the given XML snippets to deserialize the way I want?