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
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
fn join_compact<S>(self, separator: S) -> CompactString
Joins all the items of a collection, placing a separator between them, f