Enum Case
enum Case
Defines the type of casing a string can be.
use ;
let super_mario_title: String = "super_mario_64".to_case;
assert_eq!;
A case is the pair of a pattern and a delimeter (a string). Given a list of words, a pattern describes how to mutate the words and a delimeter is how the mutated words are joined together. These inherantly are the properties of what makes a "multiword identifier case", or simply "case".
This crate provides the ability to convert "from" a case. This introduces a different feature
of cases which are the word boundaries that segment the identifier into words. For example, a
snake case identifier my_var_name can be split on underscores _ to segment into words. A
camel case identifier myVarName is split where a lowercase letter is followed by an
uppercase letter. Each case is also associated with a list of boundaries that are used when
converting "from" a particular case.
Variants
-
Upper Uppercase strings are delimited by spaces and all characters are uppercase.
use ; assert_eq!-
Lower Lowercase strings are delimited by spaces and all characters are lowercase.
use ; assert_eq!-
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 ; assert_eq!-
Sentence Sentence case strings are delimited by spaces. Only the leading character of the first word is uppercase.
use ; assert_eq!-
Toggle Toggle case strings are delimited by spaces. All characters are uppercase except for the leading character of each word, which is lowercase.
use ; assert_eq!-
Camel Camel case strings are lowercase, but for every word except the first the first letter is capitalized.
- Boundaries: LowerUpper, DigitUpper, UpperDigit, DigitLower, LowerDigit, Acronym
- Pattern: Camel
- Delimeter: No delimeter
use ; assert_eq!-
Pascal Pascal case strings are lowercase, but for every word the first letter is capitalized.
- Boundaries: LowerUpper, DigitUpper, UpperDigit, DigitLower, LowerDigit, Acronym
- Pattern: Capital
- Delimeter: No delimeter
use ; assert_eq!-
UpperCamel Upper camel case is an alternative name for Pascal case.
-
Snake Snake case strings are delimited by underscores
_and are all lowercase.- Boundaries: Underscore
- Pattern: Lowercase
- Delimeter: Underscore
_
use ; assert_eq!-
Constant Constant case strings are delimited by underscores
_and are all uppercase.- Boundaries: Underscore
- Pattern: Uppercase
- Delimeter: Underscore
_
use ; assert_eq!-
UpperSnake Upper snake case is an alternative name for constant case.
-
Kebab Kebab case strings are delimited by hyphens
-and are all lowercase.use ; assert_eq!-
Cobol Cobol case strings are delimited by hyphens
-and are all uppercase.use ; assert_eq!-
UpperKebab Upper kebab case is an alternative name for Cobol case.
-
Train Train case strings are delimited by hyphens
-. All characters are lowercase except for the leading character of each word.use ; assert_eq!-
Flat Flat case strings are all lowercase, with no delimiter. Note that word boundaries are lost.
- Boundaries: No boundaries
- Pattern: Lowercase
- Delimeter: No delimeter
use ; assert_eq!-
UpperFlat Upper flat case strings are all uppercase, with no delimiter. Note that word boundaries are lost.
- Boundaries: No boundaries
- Pattern: Uppercase
- Delimeter: No delimeter
use ; assert_eq!-
Alternating Alternating case strings are delimited by spaces. Characters alternate between uppercase and lowercase.
- Boundaries: Space
- Pattern: Alternating
- Delimeter: Space
use ; assert_eq!;
Implementations
impl Case
const fn delim(self: &Self) -> &'static strReturns the delimiter used in the corresponding case. The following table outlines which cases use which delimeter.
Cases Delimeter Upper, Lower, Title, Toggle, Alternating, Random, PseudoRandom Space Snake, Constant, UpperSnake Underscore _Kebab, Cobol, UpperKebab, Train Hyphen -UpperFlat, Flat, Camel, UpperCamel, Pascal Empty string, no delimeter const fn pattern(self: &Self) -> PatternReturns the pattern used in the corresponding case. The following table outlines which cases use which pattern.
Cases Pattern Upper, Constant, UpperSnake, UpperFlat, Cobol, UpperKebab Uppercase Lower, Snake, Kebab, Flat Lowercase Title, Pascal, UpperCamel, Train Capital Camel Camel Alternating Alternating Random Random PseudoRandom PseudoRandom fn boundaries(self: &Self) -> Vec<Boundary>Returns the boundaries used in the corresponding case. That is, where can word boundaries be distinguished in a string of the given case. The table outlines which cases use which set of boundaries.
Cases Boundaries Upper, Lower, Title, Toggle, Alternating, Random, PseudoRandom Space Snake, Constant, UpperSnake Underscore _Kebab, Cobol, UpperKebab, Train Hyphen -Camel, UpperCamel, Pascal LowerUpper, LowerDigit, UpperDigit, DigitLower, DigitUpper, Acronym UpperFlat, Flat No boundaries fn all_cases() -> Vec<Case>Returns a vector with all case enum variants in no particular order.
fn deterministic_cases() -> Vec<Case>Returns a vector with all the cases that do not depend on randomness. This is all the cases not in the "random" feature.
impl Clone for Case
fn clone(self: &Self) -> Case
impl Copy for Case
impl Debug for Case
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Eq for Case
impl Freeze for Case
impl Hash for Case
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl PartialEq for Case
fn eq(self: &Self, other: &Case) -> bool
impl RefUnwindSafe for Case
impl Send for Case
impl StructuralPartialEq for Case
impl Sync for Case
impl Unpin for Case
impl UnsafeUnpin for Case
impl UnwindSafe for Case
impl<T> Any for Case
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Case
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Case
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Case
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Case
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Case
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Case
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Case
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Case
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>