pub trait CompactStringExt {
    // Required methods
    fn concat_compact(&self) -> CompactString;
    fn join_compact<S>(&self, seperator: S) -> CompactString
       where S: AsRef<str>;
}
Expand description

A trait that provides convience methods for creating a CompactString from a collection of items. It is implemented for all types that can be converted into an iterator, and that iterator yields types that can be converted into a str.

i.e. C: IntoIterator<Item = AsRef<str>>.

Concatenate and Join

Two methods that this trait provides are concat_compact(...) and join_compact(...)

use compact_str::CompactStringExt;

let words = vec!["☀️", "🌕", "🌑", "☀️"];

// directly concatenate all the words together
let concat = words.concat_compact();
assert_eq!(concat, "☀️🌕🌑☀️");

// join the words, with a seperator
let join = words.join_compact(" ➡️ ");
assert_eq!(join, "☀️ ➡️ 🌕 ➡️ 🌑 ➡️ ☀️");

Required Methods§

fn concat_compact(&self) -> CompactString

Concatenates all the items of a collection into a CompactString

Example
use compact_str::CompactStringExt;

let items = ["hello", " ", "world", "!"];
let compact = items.concat_compact();

assert_eq!(compact, "hello world!");

fn join_compact<S>(&self, seperator: S) -> CompactStringwhere S: AsRef<str>,

Joins all the items of a collection, placing a seperator between them, forming a CompactString

Example
use compact_str::CompactStringExt;

let fruits = vec!["apples", "oranges", "bananas"];
let compact = fruits.join_compact(", ");

assert_eq!(compact, "apples, oranges, bananas");

Implementors§

§

impl<I, C> CompactStringExt for Cwhere I: AsRef<str>, &'a C: for<'a> IntoIterator<Item = &'a I>,