From 308983209006129ee4c8c6fdd8fe71cbdc4ebd0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Wed, 31 Jul 2024 15:40:41 +0200 Subject: [PATCH] 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. --- parsers/src/util/macro_tests.rs | 4 ++++ xso-proc/src/structs.rs | 14 ++------------ xso/ChangeLog | 7 ------- xso/src/from_xml_doc.md | 3 +-- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/parsers/src/util/macro_tests.rs b/parsers/src/util/macro_tests.rs index 8c8c6909..82dd46fa 100644 --- a/parsers/src/util/macro_tests.rs +++ b/parsers/src/util/macro_tests.rs @@ -610,3 +610,7 @@ fn renamed_types_get_renamed() { assert!(std::mem::size_of::() >= 0); assert!(std::mem::size_of::() >= 0); } + +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = NS1, name = "elem")] +struct Foo_; diff --git a/xso-proc/src/structs.rs b/xso-proc/src/structs.rs index ea601084..ffc1e83e 100644 --- a/xso-proc/src/structs.rs +++ b/xso-proc/src/structs.rs @@ -64,16 +64,6 @@ pub(crate) struct StructDef { 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 { /// Create a new struct from its name, meta, and fields. pub(crate) fn new(ident: &Ident, meta: XmlCompoundMeta, fields: &Fields) -> Result { @@ -87,12 +77,12 @@ impl StructDef { let builder_ty_ident = match meta.builder { Some(v) => v, - None => concat_camel_case(ident, "FromXmlBuilder"), + None => quote::format_ident!("{}FromXmlBuilder", ident), }; let item_iter_ty_ident = match meta.iterator { Some(v) => v, - None => concat_camel_case(ident, "AsXmlIterator"), + None => quote::format_ident!("{}AsXmlIterator", ident), }; Ok(Self { diff --git a/xso/ChangeLog b/xso/ChangeLog index fd8b23b6..251469ce 100644 --- a/xso/ChangeLog +++ b/xso/ChangeLog @@ -1,12 +1,5 @@ Version NEXT: 0000-00-00 Jonas Schäfer - * 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 - Support for child elements in derive macros. Child elements may also be wrapped in Option or Box. diff --git a/xso/src/from_xml_doc.md b/xso/src/from_xml_doc.md index e148ea65..dad9c81d 100644 --- a/xso/src/from_xml_doc.md +++ b/xso/src/from_xml_doc.md @@ -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 `FromXmlBuilder` and the iterator type uses the type's name suffixed with -`AsXmlIterator`. If the target type has any trailing underscores, they are -removed before making the type name. +`AsXmlIterator`. ### Field meta