make default name be PascalCase

main
annieversary 2022-01-21 10:40:23 +00:00
parent 224d61d4e1
commit 15678fe80f
3 changed files with 5 additions and 12 deletions

View File

@ -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"

View File

@ -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::<String>() + c.as_str(),
}
}
#[derive(Clone, Copy)]
struct LettersIter {
idx: u32,

View File

@ -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 {