fix: resolve proc-macro reserved keyword and trait export issues

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-27 12:09:21 -03:00
parent 6579d47821
commit 697ec44f4d
6 changed files with 13 additions and 10 deletions

View File

@@ -10,3 +10,4 @@ proc-macro = true
syn = { version = "2.0", features = ["full"] }
quote = "1.0"
proc-macro2 = "1.0"
to_snake_case_trait = { path = "../to_snake_case_trait" }

View File

@@ -4,12 +4,6 @@ use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, Data, DeriveInput};
// First, define the trait that we want to implement.
// This could also live in a separate, non-proc-macro crate if you wanted.
pub trait ToSnakeCaseString {
fn to_snake_case(&self) -> String;
}
/// This is the derive macro function.
/// The `#[proc_macro_derive(ToSnakeCaseString)]` attribute tells the compiler
/// that this function implements the derive macro for the `ToSnakeCaseString` trait.
@@ -42,9 +36,9 @@ pub fn to_snake_case_string_derive(input: TokenStream) -> TokenStream {
});
// Generate the full implementation of the trait for the enum
let gen = quote! {
let generated = quote! {
// This is the implementation of our custom trait
impl ToSnakeCaseString for #name {
impl to_snake_case_trait::ToSnakeCaseString for #name {
// This is the implementation of the trait's method
fn to_snake_case(&self) -> String {
match self {
@@ -69,7 +63,7 @@ pub fn to_snake_case_string_derive(input: TokenStream) -> TokenStream {
};
// Return the generated code as a TokenStream
gen.into()
generated.into()
}
/// Helper function to convert a PascalCase string to a snake_case string.