Function fmty::join_once

source ·
pub fn join_once<I, S>(iter: I, sep: S) -> JoinOnce<I::IntoIter, S>where
    I: IntoIterator,
Expand description

Concatenates Iterator items with a separator between each, at most once.

This is a non-Clone alternative to join(). It uses interior mutability to take ownership of the iterator in the first call to Display::fmt(). As a result, JoinOnce does not implement Sync.

This is similar to Itertools::format() except that it will not panic if called more than once.

Examples

let value = fmty::join_once(["hola", "mundo"], " ");
assert_eq!(value.to_string(), "hola mundo");

assert_eq!(value.to_string(), "");