kvarn_async::prelude::compact_str

Trait CompactStringExt

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

A trait that provides convenience 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.iter().concat_compact();
assert_eq!(concat, "โ˜€๏ธ๐ŸŒ•๐ŸŒ‘โ˜€๏ธ");

// join the words, with a separator
let join = words.iter().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, separator: S) -> CompactString
where S: AsRef<str>,

Joins all the items of a collection, placing a separator between them, f