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§
Source§impl Boundary
impl Boundary
Sourcepub fn list_from(s: &str) -> Vec<Boundary>
pub fn list_from(s: &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;
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")
);Sourcepub fn defaults() -> Vec<Boundary>
pub fn defaults() -> Vec<Boundary>
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()
);Sourcepub fn delims() -> Vec<Boundary>
pub fn delims() -> Vec<Boundary>
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()
);Sourcepub fn digits() -> Vec<Boundary>
pub fn digits() -> Vec<Boundary>
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()
);Sourcepub fn letter_digit() -> Vec<Boundary>
pub fn letter_digit() -> Vec<Boundary>
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()
);Sourcepub fn digit_letter() -> Vec<Boundary>
pub fn digit_letter() -> Vec<Boundary>
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()
);Sourcepub fn all() -> Vec<Boundary>
pub fn all() -> Vec<Boundary>
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§
impl Copy for Boundary
impl Eq for Boundary
impl StructuralPartialEq for Boundary
Auto Trait Implementations§
impl Freeze for Boundary
impl RefUnwindSafe for Boundary
impl Send for Boundary
impl Sync for Boundary
impl Unpin for Boundary
impl UnwindSafe for Boundary
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more