pub trait CompactStringExt {
    fn concat_compact(&self) -> CompactString;
    fn join_compact<S: AsRef<str>>(&self, seperator: S) -> CompactString;
}
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

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!");

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