Skip to main content

Text

Trait Text 

Source
pub trait Text<'a>:
    Sized
    + Clone
    + 'a {
    // Required methods
    fn from_static_str(s: &'static str) -> Self;
    fn as_str(&self) -> Cow<'_, str>;

    // Provided methods
    fn from_static_spaces(s: &'static str) -> Self { ... }
    fn len(&self) -> usize { ... }
    fn space() -> Self { ... }
    fn newline() -> Self { ... }
    fn comma_space() -> Self { ... }
}
Expand description

Pretty printing can work with arbitrary text-like objects, as long as they implement this trait.

Required Methods§

Source

fn from_static_str(s: &'static str) -> Self

Turn a &’static str into Self, without any further knowledge about it.

Used for a bunch of functions to give a default. Often not the most optimal or even desired implementation.

Source

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

Turn custom text into a Cow<'a, str>.

Provided Methods§

Source

fn from_static_spaces(s: &'static str) -> Self

We foten insert spaces as a static str.

By default this is implemented with [from_static_str].

Source

fn len(&self) -> usize

Get the length of the custom text.

Source

fn space() -> Self

A space character

By default this is implemented with [from_static_str].

Source

fn newline() -> Self

A newline character

By default this is implemented with [from_static_str].

Source

fn comma_space() -> Self

A comma and space character

By default this is implemented with [from_static_str].

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<'a> Text<'a> for Cow<'a, str>

Source§

fn from_static_str(s: &'static str) -> Self

Source§

fn as_str(&self) -> Cow<'a, str>

Implementors§