Function display_utils::join_format [−][src]
pub fn join_format<I, J, C>(
iterator: I,
joiner: J,
callback: C
) -> JoinFormat<I::IntoIter, J, C> where
I: IntoIterator,
I::IntoIter: Clone,
J: Display,
C: Fn(I::Item, &mut Formatter<'_>) -> Result,
Concatenate iterator elements, separating each element pair with a given joiner, where each iterator element can be formatted using a callback.
The callback must be Fn and the iterator must be cloneable, because Display objects may be printed multiple times.
let strings = &["hello", "wonderful", "world"]; let output = join_format( strings.iter().enumerate(), ", ", |(i, string), f| write!(f, "{}={}", i, string), ); assert_eq!(output.to_string(), "0=hello, 1=wonderful, 2=world");