Function join_string::join

source ·
pub fn join<I, S>(elements: impl Join<I>, sep: S) -> Joiner<I, S>where
    I: Iterator,
    I::Item: Display,
    S: Display,
Expand description

Join anything that implements Join, not just iterators. The elements need to implement std::fmt::Display.

You can pass iterators, slices, and borrows of arrays and Vecs:

use join_string::join;
 
assert_eq!(
    join(&["foo", "bar", "baz"], ", ").into_string(),
    "foo, bar, baz"
);
 
assert_eq!(
    join([1, 2, 3].as_slice(), ", ").into_string(),
    "1, 2, 3"
);
 
assert_eq!(
    join(&vec!['a', 'b', 'c'], ", ").into_string(),
    "a, b, c"
);
 
assert_eq!(
    join([
        "foo".to_owned(),
        "bar".to_owned(),
        "baz".to_owned()
    ].iter().rev(), ", ").into_string(),
    "baz, bar, foo"
);