xso: add support for boxed children
This allows building recursive tree structures.
This commit is contained in:
parent
01336802b4
commit
cd9f2033f3
3 changed files with 80 additions and 2 deletions
|
|
@ -550,3 +550,40 @@ fn optional_child_roundtrip_absent() {
|
|||
};
|
||||
roundtrip_full::<OptionalChild>("<parent xmlns='urn:example:ns1'/>")
|
||||
}
|
||||
|
||||
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = NS1, name = "elem")]
|
||||
struct BoxedChild {
|
||||
#[xml(child(default))]
|
||||
child: std::option::Option<Box<BoxedChild>>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boxed_child_roundtrip_absent() {
|
||||
#[allow(unused_imports)]
|
||||
use std::{
|
||||
option::Option::{None, Some},
|
||||
result::Result::{Err, Ok},
|
||||
};
|
||||
roundtrip_full::<BoxedChild>("<elem xmlns='urn:example:ns1'/>")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boxed_child_roundtrip_nested_1() {
|
||||
#[allow(unused_imports)]
|
||||
use std::{
|
||||
option::Option::{None, Some},
|
||||
result::Result::{Err, Ok},
|
||||
};
|
||||
roundtrip_full::<BoxedChild>("<elem xmlns='urn:example:ns1'><elem/></elem>")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boxed_child_roundtrip_nested_2() {
|
||||
#[allow(unused_imports)]
|
||||
use std::{
|
||||
option::Option::{None, Some},
|
||||
result::Result::{Err, Ok},
|
||||
};
|
||||
roundtrip_full::<BoxedChild>("<elem xmlns='urn:example:ns1'><elem><elem/></elem></elem>")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue