Function join

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

Join anything that implements Join. The elements need to implement std::fmt::Display.

ยงExamples

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