use inflector::Inflector;
use proc_macro::{Literal, TokenStream, TokenTree};
#[proc_macro]
pub fn identifier_to_camel(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Ident(ref ident) => {
let ident = ident.to_string().to_camel_case();
Literal::string(&ident).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn literal_to_camel(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Literal(ref literal) => {
let literal = literal.to_string().to_camel_case();
Literal::string(&literal).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn identifier_to_kebab(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Ident(ref ident) => {
let ident = ident.to_string().to_kebab_case();
Literal::string(&ident).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn literal_to_kebab(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Literal(ref literal) => {
let literal = literal.to_string().to_kebab_case();
Literal::string(&literal).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn identifier_to_train(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Ident(ref ident) => {
let ident = ident.to_string().to_train_case();
Literal::string(&ident).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn literal_to_train(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Literal(ref literal) => {
let literal = literal.to_string().to_train_case();
Literal::string(&literal).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn identifier_to_screaming_snake(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Ident(ref ident) => {
let ident = ident.to_string().to_screaming_snake_case();
Literal::string(&ident).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn literal_to_screaming_snake(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Literal(ref literal) => {
let literal = literal.to_string().to_screaming_snake_case();
Literal::string(&literal).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn identifier_to_sentence(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Ident(ref ident) => {
let ident = ident.to_string().to_sentence_case();
Literal::string(&ident).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn literal_to_sentence(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Literal(ref literal) => {
let literal = literal.to_string().to_sentence_case();
Literal::string(&literal).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn identifier_to_snake(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Ident(ref ident) => {
let ident = ident.to_string().to_snake_case();
Literal::string(&ident).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn literal_to_snake(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Literal(ref literal) => {
let literal = literal.to_string().to_snake_case();
Literal::string(&literal).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn identifier_to_pascal(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Ident(ref ident) => {
let ident = ident.to_string().to_pascal_case();
Literal::string(&ident).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn literal_to_pascal(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Literal(ref literal) => {
let literal = literal.to_string().to_pascal_case();
Literal::string(&literal).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn identifier_to_title(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Ident(ref ident) => {
let ident = ident.to_string().to_title_case();
Literal::string(&ident).into()
}
_ => token_tree,
})
.collect()
}
#[proc_macro]
pub fn literal_to_title(stream: TokenStream) -> TokenStream {
stream
.into_iter()
.map(|token_tree| match token_tree {
TokenTree::Literal(ref literal) => {
let literal = literal.to_string().to_title_case();
Literal::string(&literal).into()
}
_ => token_tree,
})
.collect()
}