Struct Words

Source
pub struct Words<'a> { /* private fields */ }
Expand description

Sequence of words of some original string.

Divides the case style “enforcement” into two steps:

  1. Split the original string into words.
  2. Capitalise and concatenate the words into a new string.

Implementations§

Source§

impl<'a> Words<'a>

Source

pub fn with_separator(s: &'a str, sep: &Regex) -> Words<'a>

Creates a new Words of the string slice using the separator regex to split it.

Source

pub fn camel(&self) -> String

Returns the words capitalised and concatenated like camelCase as a new String.

Source

pub fn pascal(&self) -> String

Returns the words capitalised and concatenated like PascalCase as a new String.

Source

pub fn kebab(&self) -> String

Returns the words capitalised and concatenated like kebab-case as a new String.

Source

pub fn screaming_kebab(&self) -> String

Returns the words capitalised and concatenated like SCREAMING-KEBAB-CASE as a new String.

Source

pub fn lower(&self) -> String

Returns the words capitalised and concatenated like lower case as a new String.

Source

pub fn upper(&self) -> String

Returns the words capitalised and concatenated like UPPER CASE as a new String.

Source

pub fn snake(&self) -> String

Returns the words capitalised and concatenated like snake_case as a new String.

Source

pub fn screaming_snake(&self) -> String

Returns the words capitalised and concatenated like SCREAMING_SNAKE_CASE as a new String.

Source

pub fn title(&self) -> String

Returns the words capitalised and concatenated like Title Case as a new String.

Source

pub fn toggle(&self) -> String

Returns the words capitalised and concatenated like tOGGLE cASE as a new String.

Source

pub fn random(&self) -> String

Returns the words case-randomised and concatenated with a space as a new String.

Trait Implementations§

Source§

impl<'a> From<&'a str> for Words<'a>

Source§

fn from(s: &'a str) -> Self

Creates a new Words for the string slice.

The string is split into words by the following algorithm:

  1. Trim the string.
  2. If the string contains whitespace, then split it by whitespace.
  3. If the string contains hyphens ‘-’ or underscores ‘_’, then split it by whichever of them is more frequent.
  4. Split the string by case changes: ‘*|Az’ and ‘z|A*’.

Auto Trait Implementations§

§

impl<'a> Freeze for Words<'a>

§

impl<'a> RefUnwindSafe for Words<'a>

§

impl<'a> Send for Words<'a>

§

impl<'a> Sync for Words<'a>

§

impl<'a> Unpin for Words<'a>

§

impl<'a> UnwindSafe for Words<'a>

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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