Skip to content

Commit

Permalink
Allow raw identifiers for SqlIdentifier (column-name)
Browse files Browse the repository at this point in the history
This allows using the `r#identifier` syntax for SqlIdentifier
(column-name), which is used in derive macros.
Previously the derive macros would panic when encountering such an
identifier:
    `"r#identifier"` is not a valid identifier
  • Loading branch information
z33ky committed May 20, 2024
1 parent 3c7b7c4 commit dcef510
Show file tree
Hide file tree
Showing 10 changed files with 535 additions and 107 deletions.
4 changes: 3 additions & 1 deletion .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ extend-ignore-re = [
"cannot find value `titel` in module `posts`",
"cannot find type `titel` in module `posts`",
"[0-9]+[[:space]]+|[[:space:]]+titel: String",
"big_sur"
"big_sur",
# That's Spanish for "type" (used in a unit-test)
"tipe",
]

[type.md]
Expand Down
6 changes: 5 additions & 1 deletion diesel_derives/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ impl SqlIdentifier {

impl ToTokens for SqlIdentifier {
fn to_tokens(&self, tokens: &mut TokenStream) {
Ident::new(&self.field_name, self.span).to_tokens(tokens)
if self.field_name.starts_with("r#") {
Ident::new_raw(&self.field_name[2..], self.span).to_tokens(tokens)
} else {
Ident::new(&self.field_name, self.span).to_tokens(tokens)
}
}
}

Expand Down
Loading

0 comments on commit dcef510

Please sign in to comment.