pub enum Pattern {
    Lowercase,
    Uppercase,
    Capital,
    Sentence,
    Camel,
    Alternating,
    Toggle,
    PseudoRandom,
}
Expand description

A pattern is how a set of words is mutated before joining with a delimeter.

The Random and PseudoRandom patterns are used for their respective cases and are only available in the “random” feature.

Variants

Lowercase

Lowercase patterns make all words lowercase.

use convert_case::Pattern;
assert_eq!(
    vec!["case", "conversion", "library"],
    Pattern::Lowercase.mutate(&["Case", "CONVERSION", "library"])
);

Uppercase

Uppercase patterns make all words uppercase.

use convert_case::Pattern;
assert_eq!(
    vec!["CASE", "CONVERSION", "LIBRARY"],
    Pattern::Uppercase.mutate(&["Case", "CONVERSION", "library"])
);

Capital

Capital patterns makes the first letter of each word uppercase and the remaining letters of each word lowercase.

use convert_case::Pattern;
assert_eq!(
    vec!["Case", "Conversion", "Library"],
    Pattern::Capital.mutate(&["Case", "CONVERSION", "library"])
);

Sentence

Capital patterns make the first word capitalized and the remaining lowercase.

use convert_case::Pattern;
assert_eq!(
    vec!["Case", "conversion", "library"],
    Pattern::Sentence.mutate(&["Case", "CONVERSION", "library"])
);

Camel

Camel patterns make the first word lowercase and the remaining capitalized.

use convert_case::Pattern;
assert_eq!(
    vec!["case", "Conversion", "Library"],
    Pattern::Camel.mutate(&["Case", "CONVERSION", "library"])
);

Alternating

Alternating patterns make each letter of each word alternate between lowercase and uppercase. They alternate across words, which means the last letter of one word and the first letter of the next will not be the same letter casing.

use convert_case::Pattern;
assert_eq!(
    vec!["cAsE", "cOnVeRsIoN", "lIbRaRy"],
    Pattern::Alternating.mutate(&["Case", "CONVERSION", "library"])
);
assert_eq!(
    vec!["aNoThEr", "ExAmPlE"],
    Pattern::Alternating.mutate(&["Another", "Example"]),
);

Toggle

Toggle patterns have the first letter of each word uppercase and the remaining letters of each word uppercase.

use convert_case::Pattern;
assert_eq!(
    vec!["cASE", "cONVERSION", "lIBRARY"],
    Pattern::Toggle.mutate(&["Case", "CONVERSION", "library"])
);

PseudoRandom

PseudoRandom patterns are random-like patterns. Instead of randomizing each letter individually, it mutates each pair of characters as either (Lowercase, Uppercase) or (Uppercase, Lowercase). This generates more “random looking” words. A consequence of this algorithm for randomization is that there will never be three consecutive letters that are all lowercase or all uppercase. This uses the rand crate and is only available with the “random” feature. This example will not pass the assertion due to randomness, but it used as an example of what output is possible.

use convert_case::Pattern;
assert_eq!(
    vec!["cAsE", "cONveRSioN", "lIBrAry"],
    Pattern::Random.mutate(&["Case", "CONVERSION", "library"]),
);

Implementations

Generates a vector of new Strings in the right pattern given the input strings.

use convert_case::Pattern;

assert_eq!(
    vec!["crack", "the", "skye"],
    Pattern::Lowercase.mutate(&vec!["CRACK", "the", "Skye"]),
)

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 !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

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.