Struct Converter
struct Converter { ... }
The parameters for performing a case conversion.
A Converter stores three fields needed for case conversion.
boundaries: how a string is segmented into words.pattern: how words are mutated, or how each character's case will change.delimor delimeter: how the mutated words are joined into the final string.
Then calling convert on a Converter will apply a case conversion
defined by those fields. The Converter struct is what is used underneath those functions
available in the Casing struct.
You can use Converter when you need more specificity on conversion
than those provided in Casing, or if it is simply more convenient or explicit.
use ;
let s = "DialogueBox-border-shadow";
// Convert using Casing trait
assert_eq!;
// Convert using similar functions on Converter
let conv = new
.from_case
.to_case;
assert_eq!;
// Convert by setting each field explicitly.
let conv = new
.set_boundaries
.set_pattern
.set_delim;
assert_eq!;
Or you can use Converter when you are trying to make a unique case
not provided as a variant of Case.
# use ;
let dot_camel = new
.set_boundaries
.set_pattern
.set_delim;
assert_eq!;
Fields
boundaries: Vec<Boundary>How a string is segmented into words.
pattern: Option<Pattern>How each word is mutated before joining. In the case that there is no pattern, none of the words will be mutated before joining and will maintain whatever case they were in the original string.
delim: StringThe string used to join mutated words together.
Implementations
impl Converter
fn new() -> SelfCreates a new
Converterwith default fields. This is the same asDefault::default(). TheConverterwill useBoundary::defaults()for boundaries, no pattern, and an empty string as a delimeter.# use Converter; let conv = new; assert_eq!fn convert<T>(self: &Self, s: T) -> String where T: AsRef<str>Converts a string.
# use ; let conv = new .to_case; assert_eq!fn to_case(self: Self, case: Case) -> SelfSet the pattern and delimiter to those associated with the given case.
# use ; let conv = new .to_case; assert_eq!fn from_case(self: Self, case: Case) -> SelfSets the boundaries to those associated with the provided case. This is used by the
from_casefunction in theCasingtrait.# use ; let conv = new .from_case .to_case; assert_eq!fn set_boundaries(self: Self, bs: &[Boundary]) -> SelfSets the boundaries to those provided.
# use ; let conv = new .set_boundaries .to_case; assert_eq!fn add_boundary(self: Self, b: Boundary) -> SelfAdds a boundary to the list of boundaries.
# use ; let conv = new .from_case .add_boundary .to_case; assert_eq!fn add_boundaries(self: Self, bs: &[Boundary]) -> SelfAdds a vector of boundaries to the list of boundaries.
# use ; let conv = new .from_case .to_case .add_boundaries; assert_eq!;fn remove_boundary(self: Self, b: Boundary) -> SelfRemoves a boundary from the list of boundaries if it exists.
# use ; let conv = new .remove_boundary .to_case; assert_eq!;fn remove_boundaries(self: Self, bs: &[Boundary]) -> SelfRemoves all the provided boundaries from the list of boundaries if it exists.
# use ; let conv = new .remove_boundaries .to_case; assert_eq!;fn set_delim<T>(self: Self, d: T) -> Self where T: ToStringSets the delimeter.
# use ; let conv = new .to_case .set_delim; assert_eq!;fn remove_delim(self: Self) -> SelfSets the delimeter to an empty string.
# use ; let conv = new .to_case .remove_delim; assert_eq!;fn set_pattern(self: Self, p: Pattern) -> SelfSets the pattern.
# use ; let conv = new .set_delim .set_pattern; assert_eq!;fn remove_pattern(self: Self) -> SelfSets the pattern field to
None. Where there is no pattern, a character's case is never mutated and will be maintained at the end of conversion.# use ; let conv = new .from_case .to_case .remove_pattern; assert_eq!;
impl Default for Converter
fn default() -> Self
impl Freeze for Converter
impl RefUnwindSafe for Converter
impl Send for Converter
impl Sync for Converter
impl Unpin for Converter
impl UnsafeUnpin for Converter
impl UnwindSafe for Converter
impl<T> Any for Converter
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Converter
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Converter
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for Converter
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for Converter
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Converter
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Converter
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>