Struct Boundary

struct Boundary { ... }

How an identifier is split into words.

Some boundaries, HYPHEN, UNDERSCORE, and SPACE, consume the character they split on, whereas the other boundaries do not.

Boundary includes methods that return useful groups of boundaries. It also contains the defaults_from method which will generate a subset of default boundaries based on the boundaries present in a string.

You can also create custom delimiter boundaries using the from_delim method or directly instantiate Boundary for complex boundary conditions.

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

assert_eq!(
    "transformations_in_3d",
    "TransformationsIn3D"
        .from_case(Case::Camel)
        .without_boundaries(&Boundary::digit_letter())
        .to_case(Case::Snake)
);

let conv = Converter::new()
    .set_boundaries(&Boundary::defaults_from("aA "))
    .to_case(Case::Title);
assert_eq!("7empest By Tool", conv.convert("7empest byTool"));

Fields

name: &'static str

A unique name used for comparison.

condition: fn(_: &[&str], _: Option<&'static str>) -> bool

A function that determines if this boundary is present at the start of the string. Second argument is the arg field.

arg: Option<&'static str>

An optional string passed to condition at runtime. Used internally for Boundary::from_delim method.

start: usize

Where the beginning of the boundary is.

len: usize

The length of the boundary. This is the number of graphemes that are removed when splitting.

Implementations

impl Boundary

const fn from_delim(delim: &'static str) -> Boundary

Create a new boundary based on a delimiter.

# use convert_case::{Case, Converter, Boundary};
let conv = Converter::new()
    .set_boundaries(&[Boundary::from_delim("::")])
    .to_case(Case::Camel);
assert_eq!(
    "myVarName",
    conv.convert("my::var::name")
)
const fn defaults() -> [Boundary; 9]

The default list of boundaries used when Casing::to_case is called directly and in a Converter generated from Converter::new().

# use convert_case::Boundary;
assert_eq!(
    [
        Boundary::SPACE,
        Boundary::HYPHEN,
        Boundary::UNDERSCORE,
        Boundary::LOWER_UPPER,
        Boundary::ACRONYM,
        Boundary::LOWER_DIGIT,
        Boundary::UPPER_DIGIT,
        Boundary::DIGIT_LOWER,
        Boundary::DIGIT_UPPER,
    ],
    Boundary::defaults()
);
const fn digits() -> [Boundary; 4]

Returns the boundaries that involve digits. LowerDigit.

# use convert_case::Boundary;
assert_eq!(
    [
        Boundary::LOWER_DIGIT,
        Boundary::UPPER_DIGIT,
        Boundary::DIGIT_LOWER,
        Boundary::DIGIT_UPPER,
    ],
    Boundary::digits()
);
const fn letter_digit() -> [Boundary; 2]

Returns the boundaries that are letters followed by digits.

# use convert_case::Boundary;
assert_eq!(
    [
        Boundary::LOWER_DIGIT,
        Boundary::UPPER_DIGIT,
    ],
    Boundary::letter_digit()
);
fn digit_letter() -> [Boundary; 2]

Returns the boundaries that are digits followed by letters.

# use convert_case::Boundary;
assert_eq!(
    [
        Boundary::DIGIT_LOWER,
        Boundary::DIGIT_UPPER
    ],
    Boundary::digit_letter()
);
fn defaults_from(pattern: &str) -> Vec<Boundary>

Returns a list of all boundaries that are identified within the given string. Could be a short of writing out all the boundaries in a list directly. This will not identify boundary UpperLower if it also used as part of Acronym.

If you want to be very explicit and not overlap boundaries, it is recommended to use a colon character.

# use convert_case::Boundary;
assert_eq!(
    vec![
        Boundary::SPACE,
        Boundary::HYPHEN,
        Boundary::LOWER_UPPER,
        Boundary::UPPER_DIGIT,
        Boundary::DIGIT_LOWER,
    ],
    Boundary::defaults_from("aA8a -")
);
assert_eq!(
    vec![
        Boundary::UNDERSCORE,
        Boundary::LOWER_UPPER,
        Boundary::ACRONYM,
        Boundary::DIGIT_UPPER,
    ],
    Boundary::defaults_from("bD:0B:_:AAa")
);

impl Clone for Boundary

fn clone(self: &Self) -> Boundary

impl Copy for Boundary

impl Debug for Boundary

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Eq for Boundary

impl Freeze for Boundary

impl Hash for Boundary

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl PartialEq for Boundary

fn eq(self: &Self, other: &Self) -> bool

impl RefUnwindSafe for Boundary

impl Send for Boundary

impl Sync for Boundary

impl Unpin for Boundary

impl UnsafeUnpin for Boundary

impl UnwindSafe for Boundary

impl<T> Any for Boundary

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Boundary

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Boundary

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Boundary

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Boundary

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Boundary

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for Boundary

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for Boundary

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Boundary

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>