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:
@@ -62,6 +62,7 @@ uzers = "0.12.1"
|
|||||||
which = "8.0.0"
|
which = "8.0.0"
|
||||||
xdg = "2.5.2"
|
xdg = "2.5.2"
|
||||||
to_snake_case_string = { path = "./macros" }
|
to_snake_case_string = { path = "./macros" }
|
||||||
|
to_snake_case_trait = { path = "./to_snake_case_trait" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ proc-macro = true
|
|||||||
syn = { version = "2.0", features = ["full"] }
|
syn = { version = "2.0", features = ["full"] }
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
|
to_snake_case_trait = { path = "../to_snake_case_trait" }
|
||||||
|
|||||||
@@ -4,12 +4,6 @@ use proc_macro::TokenStream;
|
|||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{parse_macro_input, Data, DeriveInput};
|
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.
|
/// This is the derive macro function.
|
||||||
/// The `#[proc_macro_derive(ToSnakeCaseString)]` attribute tells the compiler
|
/// The `#[proc_macro_derive(ToSnakeCaseString)]` attribute tells the compiler
|
||||||
/// that this function implements the derive macro for the `ToSnakeCaseString` trait.
|
/// 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
|
// Generate the full implementation of the trait for the enum
|
||||||
let gen = quote! {
|
let generated = quote! {
|
||||||
// This is the implementation of our custom trait
|
// 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
|
// This is the implementation of the trait's method
|
||||||
fn to_snake_case(&self) -> String {
|
fn to_snake_case(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
@@ -69,7 +63,7 @@ pub fn to_snake_case_string_derive(input: TokenStream) -> TokenStream {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Return the generated code as a TokenStream
|
// Return the generated code as a TokenStream
|
||||||
gen.into()
|
generated.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function to convert a PascalCase string to a snake_case string.
|
/// Helper function to convert a PascalCase string to a snake_case string.
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub use args::Args;
|
|||||||
pub use common::PIPESIZE;
|
pub use common::PIPESIZE;
|
||||||
|
|
||||||
// Re-export the ToSnakeCaseString trait and derive macro
|
// Re-export the ToSnakeCaseString trait and derive macro
|
||||||
pub use to_snake_case_string::ToSnakeCaseString;
|
pub use to_snake_case_trait::ToSnakeCaseString;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|||||||
4
to_snake_case_trait/Cargo.toml
Normal file
4
to_snake_case_trait/Cargo.toml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[package]
|
||||||
|
name = "to_snake_case_trait"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
3
to_snake_case_trait/src/lib.rs
Normal file
3
to_snake_case_trait/src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub trait ToSnakeCaseString {
|
||||||
|
fn to_snake_case(&self) -> String;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user