diff --git a/instant-xml/tests/lifetime.rs b/instant-xml/tests/lifetime.rs new file mode 100644 index 0000000..3f0bf41 --- /dev/null +++ b/instant-xml/tests/lifetime.rs @@ -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#"hello"#; + assert_eq!(xml, to_string(&v).unwrap()); + assert_eq!(v, from_str(xml).unwrap()); +}