Trait Casing

trait Casing<T: AsRef<str>>

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

fn to_case(self: &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 delimeter as case. It will split on boundaries defined at [Boundary::defaults()].

use convert_case::{Case, Casing};

assert_eq!(
    "tetronimo-piece-border",
    "Tetronimo piece border".to_case(Case::Kebab)
);
fn from_case(self: &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",
    "2020-08-10 Dannie Birthday"
        .from_case(Case::Title)
        .to_case(Case::Snake)
);
fn with_boundaries(self: &Self, bs: &[Boundary]) -> StateConverter<'_, T>

Creates a StateConverter struct initialized with the boundaries provided.

use convert_case::{Boundary, Case, Casing};

assert_eq!(
    "e1_m1_hangar",
    "E1M1 Hangar"
        .with_boundaries(&[Boundary::DIGIT_UPPER, Boundary::SPACE])
        .to_case(Case::Snake)
);
fn without_boundaries(self: &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"
        .without_boundaries(&Boundary::digits())
        .to_case(Case::Snake)
);
fn is_case(self: &Self, case: Case) -> bool

Determines if self is of the given case. This is done simply by applying the conversion and seeing if the result is the same.

use convert_case::{Case, Casing};

assert!( "kebab-case-string".is_case(Case::Kebab));
assert!( "Train-Case-String".is_case(Case::Train));

assert!(!"kebab-case-string".is_case(Case::Snake));
assert!(!"kebab-case-string".is_case(Case::Train));

Implementors