Trait readable::HeadTail

source ·
pub trait HeadTail: AsRef<str> {
    // Provided methods
    fn head(&self, len: usize) -> &str { ... }
    fn head_dot(&self, len: usize) -> String { ... }
    fn tail(&self, len: usize) -> &str { ... }
    fn tail_dot(&self, len: usize) -> String { ... }
    fn head_tail(&self, head: usize, tail: usize) -> String { ... }
}
Expand description

Head/Tail characters of a str

This trait provides some functionality for cutting off a string either by the head, tail, or both, with optional ... after/before/in-between.

Anything that implements AsRef<str> can use this trait.

Provided Methods§

source

fn head(&self, len: usize) -> &str

Return the first len bytes of this str.

This will return the full str if the len is longer than the actual inner str.

Note

Input is split by char’s, not bytes.

source

fn head_dot(&self, len: usize) -> String

Same as HeadTail::head() but the String ends with ...

This will return the full string without ... if the len is longer than the actual inner str.

Note

Input is split by char’s, not bytes.

source

fn tail(&self, len: usize) -> &str

Return the last len bytes of this str.

This will return the full str if the len is longer than the actual inner str.

Note

Input is split by char’s, not bytes.

source

fn tail_dot(&self, len: usize) -> String

Same as HeadTail::tail() but returns a String starting with ...

This will return the full string without ... if the len is longer than the actual inner str.

Note

Input is split by char’s, not bytes.

source

fn head_tail(&self, head: usize, tail: usize) -> String

Return the first head bytes and last tail bytes of this string separated with ....

Note

Input is split by char’s, not bytes.

Implementors§

source§

impl<T: AsRef<str>> HeadTail for T