Add some extra borrowing tests

This commit is contained in:
Dirkjan Ochtman 2022-11-29 13:07:41 +01:00
parent 20f73b7e01
commit d2605977aa
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
use std::borrow::Cow;
use similar_asserts::assert_eq;
use instant_xml::{from_str, to_string, FromXml, ToXml};
#[derive(Debug, Eq, FromXml, PartialEq, ToXml)]
struct Foo {
bar: Bar<'static>,
}
#[derive(Debug, Eq, FromXml, PartialEq, ToXml)]
struct Bar<'a> {
baz: Cow<'a, str>,
}
#[test]
fn lifetime() {
let v = Foo {
bar: Bar {
baz: Cow::Borrowed("hello"),
},
};
let xml = r#"<Foo><Bar><baz>hello</baz></Bar></Foo>"#;
assert_eq!(xml, to_string(&v).unwrap());
assert_eq!(v, from_str(xml).unwrap());
}