xso: add support for overriding names of generated types

In 1265f4b, we introduced a change which may cause a conflict of type
names when deriving the traits on two different types. While a
workaround existed (use `mod`s to isolate the implementation), that is
ugly.

This commit allows overriding the choice of type names.
This commit is contained in:
Jonas Schäfer 2024-07-27 08:52:08 +02:00 committed by Link Mauve
commit c90752aa51
5 changed files with 77 additions and 12 deletions

View file

@ -587,3 +587,26 @@ fn boxed_child_roundtrip_nested_2() {
};
roundtrip_full::<BoxedChild>("<elem xmlns='urn:example:ns1'><elem><elem/></elem></elem>")
}
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = NS1, name = "elem", builder = RenamedBuilder, iterator = RenamedIter)]
struct RenamedTypes;
#[test]
fn renamed_types_roundtrip() {
#[allow(unused_imports)]
use std::{
option::Option::{None, Some},
result::Result::{Err, Ok},
};
roundtrip_full::<RenamedTypes>("<elem xmlns='urn:example:ns1'/>")
}
#[test]
#[allow(unused_comparisons)]
fn renamed_types_get_renamed() {
// these merely serve as a test that the types are declared with the names
// given in the attributes.
assert!(std::mem::size_of::<RenamedBuilder>() >= 0);
assert!(std::mem::size_of::<RenamedIter>() >= 0);
}