1pub trait JoinToString<T> {
4 fn join_to_string<F>(&mut self, separator: &str, f: F) -> String
5 where
6 F: FnMut(&T) -> &str;
7}
8
9impl<T, I> JoinToString<T> for I
10where
11 I: Iterator<Item = T>,
12{
13 fn join_to_string<F>(&mut self, separator: &str, mut f: F) -> String
14 where
15 F: FnMut(&T) -> &str,
16 {
17 let mut result = String::new();
18
19 if let Some(first_item) = self.next() {
20 result.push_str(f(&first_item));
21
22 for item in self {
23 result.push_str(separator);
24 result.push_str(f(&item));
25 }
26 }
27
28 result
29 }
30}