pub enum Case {
Show 16 variants Upper, Lower, Title, Toggle, Camel, Pascal, UpperCamel, Snake, UpperSnake, ScreamingSnake, Kebab, Cobol, Train, Flat, UpperFlat, Alternating,
}
Expand description

Defines the type of casing a string can be.

use convert_case::{Case, Casing};

let super_mario_title: String = "super_mario_64".to_case(Case::Title);
assert_eq!("Super Mario 64", super_mario_title);

Variants

Upper

Uppercase strings are delimited by spaces and all characters are uppercase.

use convert_case::{Case, Casing};
assert_eq!("MY VARIABLE NAME", "My variable NAME".to_case(Case::Upper))

Lower

Lowercase strings are delimited by spaces and all characters are lowercase.

use convert_case::{Case, Casing};
assert_eq!("my variable name", "My variable NAME".to_case(Case::Lower))

Title

Title case strings are delimited by spaces. Only the leading character of each word is uppercase. No inferences are made about language, so words like “as”, “to”, and “for” will still be capitalized.

use convert_case::{Case, Casing};
assert_eq!("My Variable Name", "My variable NAME".to_case(Case::Title))

Toggle

Toggle case strings are delimited by spaces. All characters are uppercase except for the leading character of each word, which is lowercase.

use convert_case::{Case, Casing};
assert_eq!("mY vARIABLE nAME", "My variable NAME".to_case(Case::Toggle))

Camel

Camel case strings are lowercase, but for every word except the first the first letter is capitalized.

use convert_case::{Case, Casing};
assert_eq!("myVariableName", "My variable NAME".to_case(Case::Camel))

Pascal

Pascal case strings are lowercase, but for every word the first letter is capitalized.

use convert_case::{Case, Casing};
assert_eq!("MyVariableName", "My variable NAME".to_case(Case::Pascal))

UpperCamel

Upper camel case is an alternative name for Pascal case.

Snake

Snake case strings are delimited by underscores _ and are all lowercase.

use convert_case::{Case, Casing};
assert_eq!("my_variable_name", "My variable NAME".to_case(Case::Snake))

UpperSnake

Upper snake case strings are delimited by underscores _ and are all uppercase.

use convert_case::{Case, Casing};
assert_eq!("MY_VARIABLE_NAME", "My variable NAME".to_case(Case::UpperSnake))

ScreamingSnake

Screaming snake case is an alternative name for upper snake case.

Kebab

Kebab case strings are delimited by hyphens - and are all lowercase.

use convert_case::{Case, Casing};
assert_eq!("my-variable-name", "My variable NAME".to_case(Case::Kebab))

Cobol

Cobol case strings are delimited by hyphens - and are all uppercase.

use convert_case::{Case, Casing};
assert_eq!("MY-VARIABLE-NAME", "My variable NAME".to_case(Case::Cobol))

Train

Train case strings are delimited by hyphens -. All characters are lowercase except for the leading character of each word.

use convert_case::{Case, Casing};
assert_eq!("My-Variable-Name", "My variable NAME".to_case(Case::Train))

Flat

Flat case strings are all lowercase, with no delimiter. Converting to this case is lossy. That is, word boundaries are lost.

use convert_case::{Case, Casing};
assert_eq!("myvariablename", "My variable NAME".to_case(Case::Flat))

UpperFlat

Upper flat case strings are all uppercase, with no delimiter. Converting to this case is lossy. That is, word boundaries are lost.

use convert_case::{Case, Casing};
assert_eq!("MYVARIABLENAME", "My variable NAME".to_case(Case::UpperFlat))

Alternating

Alternating case strings are delimited by spaces. Characters alternate between uppercase and lowercase.

use convert_case::{Case, Casing};
assert_eq!("mY vArIaBlE nAmE", "My variable NAME".to_case(Case::Alternating));

Implementations

Returns a vector with all case enum variants. This was created for use in the ccase binary.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.