Skip to main content

CaseStyle

Enum CaseStyle 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn validate(self, value: &str) -> Result<(), CaseStyleValidationError>

Validates that a string strictly matches this naming style.

§Parameters
  • value - String to validate.
§Returns

Returns Ok(()) when value is a non-empty ASCII identifier matching this style. Returns CaseStyleValidationError carrying this style and the original value otherwise.

Source

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.

Source

pub fn matches(self, value: &str) -> bool

Tests whether a string strictly matches this naming style.

§Parameters
  • value - String to test.
§Returns

Returns true if value is non-empty and follows this style’s ASCII identifier rules; otherwise returns false.

Trait Implementations§

Source§

impl Clone for CaseStyle

Source§

fn clone(&self) -> CaseStyle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CaseStyle

Source§

impl Debug for CaseStyle

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for CaseStyle

Source§

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

Formats this naming style using its canonical name.

§Parameters
  • f - Formatter receiving the canonical name.
§Returns

Returns the formatter result.

Source§

impl Eq for CaseStyle

Source§

impl FromStr for CaseStyle

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a naming style from a string.

§Parameters
  • s - Naming style name to parse.
§Returns

Returns the parsed style, or CaseStyleError when s is unknown.

Source§

type Err = CaseStyleError

The associated error which can be returned from parsing.
Source§

impl Hash for CaseStyle

Source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CaseStyle

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CaseStyle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.