Crate join_string
source ·Expand description
A simple crate to join the elements of iterators, interspersing a separator between all elements.
This is done somewhat efficiently, if possible, meaning if the iterator is cheaply clonable you can
directly print the result of Join::join()
without creating a temporary String
in memory.
use join_string::Join;
assert_eq!(
"foo bar baz".split_whitespace().join(", ").into_string(),
"foo, bar, baz");
println!("{}",
"foo bar baz".split_whitespace()
.map(|s| s.chars().rev().join(""))
.join(' '));
// Output: oof rab zab
Structs
- Iterator-facade that maps an iterator over
AsRef<str>
to an iterator overDisplayWrapper
. - Helper for joining elements that only implement
AsRef<str>
, but notstd::fmt::Display
. - Helper struct that captures the iterator and separator for later joining.
Traits
- Trait that provides a method to join elements of an iterator, interspersing a separator between all elements.
Functions
- Join anything that implements
Join
, not just iterators. The elements need to implementstd::fmt::Display
. - Join anything that implements
Join
, not just iterators when elements don’t implementstd::fmt::Display
, but implementAsRef<str>
instead.