Expand description
Convert identifiers and string literals to different case styles
§Motivation
I wanted a macro to convert identifiers to camel case string literals for use in a project, but I only found one that converted to pascal case. So, I forked it and added support for all the case styles you could ever want, so no one else has the same problem I had. I also added support for converting string literals, because why not?
§Installation
Add it to your project with cargo:
cargo add case_conv_macros§Example
use case_conv_macros::{identifier_to_camel, literal_to_sentence};
let my_rusty_identifier = identifier_to_camel!(my_rusty_identifier);
assert_eq!(my_rusty_identifier, "myRustyIdentifier");
let my_rusty_literal = literal_to_sentence!("my_rusty_literal");
assert_eq!(my_rusty_literal, "My rusty literal");Macros§
- identifier_
to_ camel - Convert an identifier to a camel case string literal
e.g.
my_rusty_identifierbecomes"myRustyIdentifier" - identifier_
to_ kebab - Convert an identifier to a kebab case string literal
e.g.
my_rusty_identifierbecomes"my-rusty-identifier" - identifier_
to_ pascal - Convert an identifier to a pascal case string literal
e.g.
my_rusty_identifierbecomes"MyRustyIdentifier" - identifier_
to_ screaming_ snake - Convert an identifier to a screaming snake case string literal
e.g.
myRustyIdentifierbecomes"MY_RUSTY_IDENTIFIER" - identifier_
to_ sentence - Convert an identifier to a sentence case string literal
e.g.
my_rusty_identifierbecomes"My rusty identifier" - identifier_
to_ snake - Convert an identifier to a snake case string literal
e.g.
myRustyIdentifierbecomes"my_rusty_identifier" - identifier_
to_ title - Convert an identifier to a title case string literal
e.g.
my_identifier_is_rustybecomes"My Identifier Is Rusty" - identifier_
to_ train - Convert an identifier to a train case string literal
e.g.
my_rusty_identifierbecomes"My-Rusty-Identifier" - literal_
to_ camel - Convert a string literal to a camel case literal
e.g.
"my_rusty_literal"becomes"myRustyLiteral" - literal_
to_ kebab - Convert a string literal to a kebab case literal
e.g.
"my_rusty_literal"becomes"my-rusty-literal" - literal_
to_ pascal - Convert a string literal to a pascal case literal
e.g.
"my_rusty_literal"becomes"MyRustyLiteral" - literal_
to_ screaming_ snake - Convert a string literal to a screaming snake case literal
e.g.
"myRustyLiteral"becomes"MY_RUSTY_IDENTIFIER" - literal_
to_ sentence - Convert a string literal to a sentence case literal
e.g.
"my_rusty_literal"becomes"My rusty literal" - literal_
to_ snake - Convert a string literal to a snake case literal
e.g.
"myRustyLiteral"becomes"my_rusty_literal" - literal_
to_ title - Convert a string literal to a title case literal
e.g.
"my_literal_is_rusty"becomes"My Literal Is Rusty" - literal_
to_ train - Convert a string literal to a train case literal
e.g.
"my_rusty_literal"becomes"My-Rusty-Literal"