xso-proc: remove stripping of trailing _ from type names
Users can now rename the generated types altogether, which means that we do not need this anymore to avoid lints.
This commit is contained in:
parent
c90752aa51
commit
3089832090
4 changed files with 7 additions and 21 deletions
|
|
@ -610,3 +610,7 @@ fn renamed_types_get_renamed() {
|
||||||
assert!(std::mem::size_of::<RenamedBuilder>() >= 0);
|
assert!(std::mem::size_of::<RenamedBuilder>() >= 0);
|
||||||
assert!(std::mem::size_of::<RenamedIter>() >= 0);
|
assert!(std::mem::size_of::<RenamedIter>() >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
|
||||||
|
#[xml(namespace = NS1, name = "elem")]
|
||||||
|
struct Foo_;
|
||||||
|
|
|
||||||
|
|
@ -64,16 +64,6 @@ pub(crate) struct StructDef {
|
||||||
debug: bool,
|
debug: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn concat_camel_case(lhs: &Ident, suffix: &str) -> Ident {
|
|
||||||
let span = lhs.span();
|
|
||||||
let mut s = lhs.to_string();
|
|
||||||
while s.ends_with('_') {
|
|
||||||
s.pop();
|
|
||||||
}
|
|
||||||
s.push_str(suffix);
|
|
||||||
Ident::new(&s, span)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StructDef {
|
impl StructDef {
|
||||||
/// Create a new struct from its name, meta, and fields.
|
/// Create a new struct from its name, meta, and fields.
|
||||||
pub(crate) fn new(ident: &Ident, meta: XmlCompoundMeta, fields: &Fields) -> Result<Self> {
|
pub(crate) fn new(ident: &Ident, meta: XmlCompoundMeta, fields: &Fields) -> Result<Self> {
|
||||||
|
|
@ -87,12 +77,12 @@ impl StructDef {
|
||||||
|
|
||||||
let builder_ty_ident = match meta.builder {
|
let builder_ty_ident = match meta.builder {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => concat_camel_case(ident, "FromXmlBuilder"),
|
None => quote::format_ident!("{}FromXmlBuilder", ident),
|
||||||
};
|
};
|
||||||
|
|
||||||
let item_iter_ty_ident = match meta.iterator {
|
let item_iter_ty_ident = match meta.iterator {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => concat_camel_case(ident, "AsXmlIterator"),
|
None => quote::format_ident!("{}AsXmlIterator", ident),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,5 @@
|
||||||
Version NEXT:
|
Version NEXT:
|
||||||
0000-00-00 Jonas Schäfer <jonas@zombofant.net>
|
0000-00-00 Jonas Schäfer <jonas@zombofant.net>
|
||||||
* Breaking
|
|
||||||
- We now strip trailing underscores from identifiers before constructing
|
|
||||||
any type names we declare from derive macros.
|
|
||||||
|
|
||||||
If you previously derived any of the macros on e.g. `Foo` and `Foo_`
|
|
||||||
within the same scope, you can use the newly added `builder` and
|
|
||||||
`iterator` meta keys to override the generated type names.
|
|
||||||
* Added
|
* Added
|
||||||
- Support for child elements in derive macros. Child elements may also
|
- Support for child elements in derive macros. Child elements may also
|
||||||
be wrapped in Option or Box.
|
be wrapped in Option or Box.
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,7 @@ identifiers passed to either of these keys is considered reserved.
|
||||||
|
|
||||||
By default, the builder type uses the type's name suffixed with
|
By default, the builder type uses the type's name suffixed with
|
||||||
`FromXmlBuilder` and the iterator type uses the type's name suffixed with
|
`FromXmlBuilder` and the iterator type uses the type's name suffixed with
|
||||||
`AsXmlIterator`. If the target type has any trailing underscores, they are
|
`AsXmlIterator`.
|
||||||
removed before making the type name.
|
|
||||||
|
|
||||||
### Field meta
|
### Field meta
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue