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 e925fd9
Show file tree
Hide file tree
Showing 8 changed files with 515 additions and 103 deletions.
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 e925fd9

Please sign in to comment.