Enum convert_case::Boundary[][src]

pub enum Boundary {
    Hyphen,
    Underscore,
    Space,
    UpperLower,
    LowerUpper,
    DigitUpper,
    UpperDigit,
    DigitLower,
    LowerDigit,
    Acronym,
}
Expand description

A boundary defines how a string is split into words. Some boundaries, Hyphen, Underscore, and Space, consume the character they split on, whereas the other boundaries do not.

The struct offers methods that return Vecs containing useful groups of boundaries. It also contains the list_from method which will generate a list of boundaries based on a string slice.

Note that all boundaries are distinct and do not share functionality. That is, there is no such DigitLetter variant, because that would be equivalent to the current DigitUpper and DigitLower variants. For common functionality, consider using some provided functions that return a list of boundaries.

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::list_from("aA "))
    .to_case(Case::Title);
assert_eq!("7empest By Tool", conv.convert("7empest byTool"));

Variants

Hyphen

Splits on -, consuming the character on segmentation.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::Hyphen],
    Boundary::list_from("-")
);

Underscore

Splits on _, consuming the character on segmentation.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::Underscore],
    Boundary::list_from("_")
);

Space

Splits on space, consuming the character on segmentation.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::Space],
    Boundary::list_from(" ")
);

UpperLower

Splits where an uppercase letter is followed by a lowercase letter. This is seldom used, and is not included in the defaults.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::UpperLower],
    Boundary::list_from("Aa")
);

LowerUpper

Splits where a lowercase letter is followed by an uppercase letter.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::LowerUpper],
    Boundary::list_from("aA")
);

DigitUpper

Splits where digit is followed by an uppercase letter.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::DigitUpper],
    Boundary::list_from("1A")
);

UpperDigit

Splits where an uppercase letter is followed by a digit.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::UpperDigit],
    Boundary::list_from("A1")
);

DigitLower

Splits where digit is followed by a lowercase letter.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::DigitLower],
    Boundary::list_from("1a")
);

LowerDigit

Splits where a lowercase letter is followed by a digit.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::LowerDigit],
    Boundary::list_from("a1")
);

Acronym

Acronyms are identified by two uppercase letters followed by a lowercase letter. The word boundary is between the two uppercase letters. For example, “HTTPRequest” would have an acronym boundary identified at “PRe” and split into “HTTP” and “Request”.

use convert_case::Boundary;
assert_eq!(
    vec![Boundary::Acronym],
    Boundary::list_from("AAa")
);

Implementations

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;
use Boundary::*;
assert_eq!(
    vec![Hyphen, Space, LowerUpper, UpperDigit, DigitLower],
    Boundary::list_from("aA8a -")
);
assert_eq!(
    vec![Underscore, LowerUpper, DigitUpper, Acronym],
    Boundary::list_from("bD:0B:_:AAa")
);

The default list of boundaries used when Casing::to_case is called directly and in a Converter generated from Converter::new(). This includes all the boundaries except the UpperLower boundary.

use convert_case::Boundary;
use Boundary::*;
assert_eq!(
    vec![
        Underscore, Hyphen, Space, LowerUpper, UpperDigit, 
        DigitUpper, DigitLower, LowerDigit, Acronym,
    ],
    Boundary::defaults()
);

Returns the boundaries that split around single characters: Hyphen, Underscore, and Space.

use convert_case::Boundary;
use Boundary::*;
assert_eq!(
    vec![Hyphen, Underscore, Space],
    Boundary::delims()
);

Returns the boundaries that involve digits: DigitUpper, DigitLower, UpperDigit, and LowerDigit.

use convert_case::Boundary;
use Boundary::*;
assert_eq!(
    vec![DigitUpper, UpperDigit, DigitLower, LowerDigit],
    Boundary::digits()
);

Returns the boundaries that are letters followed by digits: UpperDigit and LowerDigit.

use convert_case::Boundary;
use Boundary::*;
assert_eq!(
    vec![UpperDigit, LowerDigit],
    Boundary::letter_digit()
);

Returns the boundaries that are digits followed by letters: DigitUpper and DigitLower.

use convert_case::Boundary;
use Boundary::*;
assert_eq!(
    vec![DigitUpper, DigitLower],
    Boundary::digit_letter()
);

Returns all boundaries. Note that this includes the UpperLower variant which might be unhelpful. Please look at Boundary::defaults.

use convert_case::Boundary;
use Boundary::*;
assert_eq!(
    vec![
        Hyphen, Underscore, Space, LowerUpper, UpperLower, DigitUpper,
        UpperDigit, DigitLower, LowerDigit, Acronym,
    ],
    Boundary::all()
);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.