[−][src]Enum convert_case::Case
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);
You can also create a case from a string slice.
use convert_case::{Case, Casing}; use std::convert::TryFrom; let snake_case: Case = Case::try_from("snake").unwrap(); assert_eq!(Case::Snake, snake_case);
Variants
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))
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 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 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 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 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))
Upper camel case is an alternative name for Pascal case.
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))
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))
Screaming snake case is an alternative name for upper snake case.
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 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 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 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))
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 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
impl Case
[src]
pub fn name_in_case(self) -> String
[src]
Prints the name of the case in that case.
use convert_case::Case; assert_eq!("UpperCamelCase", Case::UpperCamel.name_in_case()); assert_eq!("snake_case", Case::Snake.name_in_case()); assert_eq!("Title Case", Case::Title.name_in_case());
Trait Implementations
impl Clone for Case
[src]
impl Copy for Case
[src]
impl Debug for Case
[src]
impl Eq for Case
[src]
impl PartialEq<Case> for Case
[src]
impl StructuralEq for Case
[src]
impl StructuralPartialEq for Case
[src]
impl<'_> TryFrom<&'_ str> for Case
[src]
Auto Trait Implementations
impl RefUnwindSafe for Case
impl Send for Case
impl Sync for Case
impl Unpin for Case
impl UnwindSafe for Case
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,