Improve support for raw identifier field names

This commit is contained in:
Dirkjan Ochtman 2023-02-22 21:30:36 +01:00
parent 6c4cd8bd55
commit 8c2964b318
2 changed files with 6 additions and 2 deletions

View File

@ -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(),

View File

@ -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,