Trait StrTools

Source
pub trait StrTools: Sealed {
    // Required methods
    fn sub_nearest(&self, range: impl Range) -> &str;
    fn capitalise(&self) -> Cow<'_, str>;
    fn decapitalise(&self) -> Cow<'_, str>;
}
Available on crate feature string only.
Expand description

The main StrTools extension trait.

Required Methods§

Source

fn sub_nearest(&self, range: impl Range) -> &str

A substring method which truncates strings at the nearest UTF-8 code rather than panicking.

§Panics

This function still panics if the given range is out of bounds. It however does not panic if the passed range falls withing a UTF-8 code.

Source

fn capitalise(&self) -> Cow<'_, str>

A string capitalize function which operates on UTF-8 strings.

Source

fn decapitalise(&self) -> Cow<'_, str>

A string decapitalize function which operates on UTF-8 strings. This essentially does the inverse of the capitalise function.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl StrTools for str

Source§

fn sub_nearest(&self, range: impl Range) -> &str

Source§

fn capitalise(&self) -> Cow<'_, str>

Source§

fn decapitalise(&self) -> Cow<'_, str>

Implementors§