Add support for generic type arguments
This commit is contained in:
parent
413ec05c52
commit
055a654a3d
|
@ -79,6 +79,12 @@ impl<'input> ContainerMeta<'input> {
|
||||||
.extend(xml_generics.lifetimes().map(|lt| lt.lifetime.clone()));
|
.extend(xml_generics.lifetimes().map(|lt| lt.lifetime.clone()));
|
||||||
xml_generics.params.push(xml.into());
|
xml_generics.params.push(xml.into());
|
||||||
|
|
||||||
|
for param in xml_generics.type_params_mut() {
|
||||||
|
param
|
||||||
|
.bounds
|
||||||
|
.push(syn::parse_str("::instant_xml::FromXml<'xml>").unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
xml_generics
|
xml_generics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,14 @@ fn serialize_struct(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
let mut generics = input.generics.clone();
|
||||||
|
for param in generics.type_params_mut() {
|
||||||
|
param
|
||||||
|
.bounds
|
||||||
|
.push(syn::parse_str("::instant_xml::ToXml").unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||||
let tag = meta.tag();
|
let tag = meta.tag();
|
||||||
let ident = &input.ident;
|
let ident = &input.ident;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
use instant_xml::{from_str, to_string, FromXml, ToXml};
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, FromXml, ToXml, PartialEq)]
|
||||||
|
struct Foo<T> {
|
||||||
|
inner: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, FromXml, ToXml, PartialEq)]
|
||||||
|
struct Bar {
|
||||||
|
bar: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::disallowed_names)]
|
||||||
|
#[test]
|
||||||
|
fn serialize_generics() {
|
||||||
|
let foo = Foo {
|
||||||
|
inner: Bar {
|
||||||
|
bar: "Bar".to_owned(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let xml = "<Foo><Bar><bar>Bar</bar></Bar></Foo>";
|
||||||
|
|
||||||
|
assert_eq!(to_string(&foo).unwrap(), xml);
|
||||||
|
assert_eq!(from_str::<Foo<Bar>>(xml).unwrap(), foo);
|
||||||
|
}
|
Loading…
Reference in New Issue