diff --git a/effers-derive/Cargo.toml b/effers-derive/Cargo.toml index 8983a95..da158cc 100644 --- a/effers-derive/Cargo.toml +++ b/effers-derive/Cargo.toml @@ -10,3 +10,4 @@ proc-macro = true syn = {version = "1.0", features = ["full", "extra-traits", "visit-mut"]} quote = "1.0" proc-macro2 = "1.0" +convert_case = "0.5.0" diff --git a/effers-derive/src/lib.rs b/effers-derive/src/lib.rs index 2b63b96..fdaa407 100644 --- a/effers-derive/src/lib.rs +++ b/effers-derive/src/lib.rs @@ -1,3 +1,4 @@ +use convert_case::{Case, Casing}; use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::token::{Mut, SelfValue}; @@ -16,7 +17,7 @@ pub fn program( let mut args = parse_macro_input!(attr as Args); if args.name.is_none() { - let i = first_letter_to_uppper_case(item.sig.ident.to_string()); + let i = item.sig.ident.to_string().to_case(Case::Pascal); args.name = Some(Ident::new(&i, Span::call_site())); } @@ -29,15 +30,6 @@ pub fn program( proc_macro::TokenStream::from(out) } -// TODO change this to change from camel_case to PascalCase -fn first_letter_to_uppper_case(s1: String) -> String { - let mut c = s1.chars(); - match c.next() { - None => String::new(), - Some(f) => f.to_uppercase().collect::() + c.as_str(), - } -} - #[derive(Clone, Copy)] struct LettersIter { idx: u32, diff --git a/examples/main.rs b/examples/main.rs index 4e475a1..35b11fe 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -11,7 +11,7 @@ fn smth(val: u8) -> u8 { } #[program(Printer(print as p))] -fn other() { +fn other_program() { p("hey hi hello"); } @@ -28,7 +28,7 @@ fn main() { assert_eq!(other_result, 11); // other program - Other.add(IoPrinter).run(); + OtherProgram.add(IoPrinter).run(); } trait Printer {