From 697ec44f4d389014656f410b9b70afa882c3927c Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 27 Aug 2025 12:09:21 -0300 Subject: [PATCH] fix: resolve proc-macro reserved keyword and trait export issues Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- Cargo.toml | 1 + macros/Cargo.toml | 1 + macros/src/lib.rs | 12 +++--------- src/lib.rs | 2 +- to_snake_case_trait/Cargo.toml | 4 ++++ to_snake_case_trait/src/lib.rs | 3 +++ 6 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 to_snake_case_trait/Cargo.toml create mode 100644 to_snake_case_trait/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index fbcbd30..ed08a04 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,7 @@ uzers = "0.12.1" which = "8.0.0" xdg = "2.5.2" to_snake_case_string = { path = "./macros" } +to_snake_case_trait = { path = "./to_snake_case_trait" } [dev-dependencies] tempfile = "3.3.0" diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 0763340..01ccf06 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -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" } diff --git a/macros/src/lib.rs b/macros/src/lib.rs index dbe17ea..592d3ec 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -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. diff --git a/src/lib.rs b/src/lib.rs index 36e77da..6c482da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ pub use args::Args; pub use common::PIPESIZE; // Re-export the ToSnakeCaseString trait and derive macro -pub use to_snake_case_string::ToSnakeCaseString; +pub use to_snake_case_trait::ToSnakeCaseString; #[cfg(test)] mod tests; diff --git a/to_snake_case_trait/Cargo.toml b/to_snake_case_trait/Cargo.toml new file mode 100644 index 0000000..677a760 --- /dev/null +++ b/to_snake_case_trait/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "to_snake_case_trait" +version = "0.1.0" +edition = "2024" diff --git a/to_snake_case_trait/src/lib.rs b/to_snake_case_trait/src/lib.rs new file mode 100644 index 0000000..ddd93b0 --- /dev/null +++ b/to_snake_case_trait/src/lib.rs @@ -0,0 +1,3 @@ +pub trait ToSnakeCaseString { + fn to_snake_case(&self) -> String; +}