pub enum CaseStyle {
LowerHyphen,
LowerUnderscore,
LowerCamel,
UpperCamel,
UpperUnderscore,
}Expand description
Naming styles supported by this crate.
The conversion rules are intended for ASCII identifiers. Non-ASCII input is accepted on a best-effort basis, but its exact conversion behavior is not a stable contract.
Variants§
LowerHyphen
Hyphen separated lowercase words, such as lower-hyphen.
LowerUnderscore
Underscore separated lowercase words, such as lower_underscore.
LowerCamel
Lower camel case words, such as lowerCamel.
UpperCamel
Upper camel case words, such as UpperCamel.
UpperUnderscore
Underscore separated uppercase words, such as UPPER_UNDERSCORE.
Implementations§
Source§impl CaseStyle
impl CaseStyle
Sourcepub const fn values() -> &'static [Self]
pub const fn values() -> &'static [Self]
Returns all supported naming styles in the reference implementation order.
§Returns
Returns a static slice containing all naming styles.
Sourcepub fn of(name: &str) -> Result<Self, CaseStyleError>
pub fn of(name: &str) -> Result<Self, CaseStyleError>
Parses a naming style from its canonical name.
The comparison is case-insensitive, and hyphen and underscore are treated as equivalent separators.
§Parameters
name- Naming style name to parse.
§Returns
Returns the parsed naming style, or CaseStyleError carrying the
original name when no style matches.
Sourcepub const fn name(self) -> &'static str
pub const fn name(self) -> &'static str
Returns the canonical name of this naming style.
§Returns
Returns the lower-hyphen style name used by the JavaScript reference implementation.
Sourcepub const fn word_separator(self) -> &'static str
pub const fn word_separator(self) -> &'static str
Returns the word separator inserted by this naming style.
§Returns
Returns "-" for lower hyphen, "_" for underscore styles, and ""
for camel case styles.
Sourcepub fn to(self, target: Self, value: &str) -> String
pub fn to(self, target: Self, value: &str) -> String
Converts a string from this style to the target style.
§Parameters
target- Target naming style.value- Source string. It should be an ASCII identifier in this style. Invalid input is still converted on a best-effort basis.
§Returns
Returns the converted string. Empty input is returned as an empty
string. This permissive method neither validates the source value nor
guarantees that invalid input will match the target style. Use
Self::checked_to when the source value must be validated first.
Sourcepub fn checked_to(
self,
target: Self,
value: &str,
) -> Result<String, CaseStyleValidationError>
pub fn checked_to( self, target: Self, value: &str, ) -> Result<String, CaseStyleValidationError>
Converts a validated string from this style to the target style.
§Parameters
target- Target naming style.value- Source string to validate and convert.
§Returns
Returns the converted string when value matches this source style.
Returns CaseStyleValidationError without converting when validation
fails.