From 8c2964b318b3fdb99823cffcfe28e896aca4531e Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 22 Feb 2023 21:30:36 +0100 Subject: [PATCH] Improve support for raw identifier field names --- instant-xml-macros/src/case.rs | 6 +++++- instant-xml/tests/de-nested.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/instant-xml-macros/src/case.rs b/instant-xml-macros/src/case.rs index 540a141..aeef600 100644 --- a/instant-xml-macros/src/case.rs +++ b/instant-xml-macros/src/case.rs @@ -95,7 +95,11 @@ impl RenameRule { /// Apply a renaming rule to a struct field, returning the version expected in the source. pub fn apply_to_field(&self, ident: &Ident) -> String { - let field = ident.to_string(); + let mut field = ident.to_string(); + if field.starts_with("r#") { + field = field[2..].to_string(); + } + match *self { None | LowerCase | SnakeCase => field, UpperCase => field.to_ascii_uppercase(), diff --git a/instant-xml/tests/de-nested.rs b/instant-xml/tests/de-nested.rs index 9a80a44..196d148 100644 --- a/instant-xml/tests/de-nested.rs +++ b/instant-xml/tests/de-nested.rs @@ -13,7 +13,7 @@ struct NestedDe { #[xml(ns("URI", bar = "BAZ", foo = "BAR"))] struct StructWithCustomFieldFromXml { #[xml(ns(BAR))] - flag: bool, + r#flag: bool, #[xml(attribute)] flag_attribute: bool, test: NestedDe,