Skip to main content

Crate case_conv_macros

Crate case_conv_macros 

Source
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_identifier becomes "myRustyIdentifier"
identifier_to_kebab
Convert an identifier to a kebab case string literal e.g. my_rusty_identifier becomes "my-rusty-identifier"
identifier_to_pascal
Convert an identifier to a pascal case string literal e.g. my_rusty_identifier becomes "MyRustyIdentifier"
identifier_to_screaming_snake
Convert an identifier to a screaming snake case string literal e.g. myRustyIdentifier becomes "MY_RUSTY_IDENTIFIER"
identifier_to_sentence
Convert an identifier to a sentence case string literal e.g. my_rusty_identifier becomes "My rusty identifier"
identifier_to_snake
Convert an identifier to a snake case string literal e.g. myRustyIdentifier becomes "my_rusty_identifier"
identifier_to_title
Convert an identifier to a title case string literal e.g. my_identifier_is_rusty becomes "My Identifier Is Rusty"
identifier_to_train
Convert an identifier to a train case string literal e.g. my_rusty_identifier becomes "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"