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 LOWER_HYPHEN: Self = Self::LowerHyphen

XML hyphenated variable naming style, such as lower-hyphen.

Source

pub const LOWER_UNDERSCORE: Self = Self::LowerUnderscore

C++/Python variable naming style, such as lower_underscore.

Source

pub const LOWER_CAMEL: Self = Self::LowerCamel

Java variable naming style, such as lowerCamel.

Source

pub const UPPER_CAMEL: Self = Self::UpperCamel

Java and C++ class naming style, such as UpperCamel.

Source

pub const UPPER_UNDERSCORE: Self = Self::UpperUnderscore

Java and C++ constant naming style, such as UPPER_UNDERSCORE.

Source

pub const fn values() -> &'static [Self; 5]

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; if it is not, conversion is best-effort.
§Returns

Returns the converted string. Empty input is returned as an empty string.

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 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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, 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.