pub trait Casing<T: AsRef<str>> {
// Required methods
fn to_case(&self, case: Case<'_>) -> String;
fn from_case(&self, case: Case<'_>) -> StateConverter<'_, T>;
fn set_boundaries(&self, bs: &[Boundary]) -> StateConverter<'_, T>;
fn remove_boundaries(&self, bs: &[Boundary]) -> StateConverter<'_, T>;
fn remove_empty(&self) -> StateConverter<'_, T>;
}Expand description
Describes items that can be converted into a case. This trait is used
in conjunction with the StateConverter struct which is returned from a couple
methods on Casing.
Required Methods§
Sourcefn to_case(&self, case: Case<'_>) -> String
fn to_case(&self, case: Case<'_>) -> String
Convert the string into the given case. It will reference self and create a new
String with the same pattern and delimiter as case. It will split on boundaries
defined at Boundary::defaults().
use convert_case::{Case, Casing};
assert_eq!(
"Tetronimo piece border".to_case(Case::Kebab),
"tetronimo-piece-border",
);Sourcefn from_case(&self, case: Case<'_>) -> StateConverter<'_, T>
fn from_case(&self, case: Case<'_>) -> StateConverter<'_, T>
Start the case conversion by storing the boundaries associated with the given case.
use convert_case::{Case, Casing};
assert_eq!(
"2020-08-10 Dannie Birthday"
.from_case(Case::Title)
.to_case(Case::Snake),
"2020-08-10_dannie_birthday",
);Sourcefn set_boundaries(&self, bs: &[Boundary]) -> StateConverter<'_, T>
fn set_boundaries(&self, bs: &[Boundary]) -> StateConverter<'_, T>
Creates a StateConverter struct initialized with the boundaries provided.
use convert_case::{Boundary, Case, Casing};
assert_eq!(
"E1M1 Hangar"
.set_boundaries(&[Boundary::DigitUpper, Boundary::Space])
.to_case(Case::Snake),
"e1_m1_hangar",
);Sourcefn remove_boundaries(&self, bs: &[Boundary]) -> StateConverter<'_, T>
fn remove_boundaries(&self, bs: &[Boundary]) -> StateConverter<'_, T>
Creates a StateConverter struct initialized without the boundaries
provided.
use convert_case::{Boundary, Case, Casing};
assert_eq!(
"2d_transformation",
"2dTransformation"
.remove_boundaries(&Boundary::digits())
.to_case(Case::Snake)
);Sourcefn remove_empty(&self) -> StateConverter<'_, T>
fn remove_empty(&self) -> StateConverter<'_, T>
Creates a StateConverter with the RemoveEmpty pattern prepended.
This filters out empty words before conversion, useful when splitting
produces empty words from leading, trailing, and duplicate delimiters.
use convert_case::{Case, Casing};
assert_eq!(
"--leading-delims"
.from_case(Case::Kebab)
.remove_empty()
.to_case(Case::Camel),
"leadingDelims",
);