tiberius/tds/codec/
iterator_ext.rs
1use std::fmt::{Display, Write};
2
3pub(crate) trait IteratorJoin {
4 fn join(self, sep: &str) -> String;
5}
6
7impl<T, I> IteratorJoin for T
8where
9 T: Iterator<Item = I>,
10 I: Display,
11{
12 fn join(mut self, sep: &str) -> String {
13 let (lower_bound, _) = self.size_hint();
14 let mut out = String::with_capacity(sep.len() * lower_bound);
15
16 if let Some(first_item) = self.next() {
17 write!(out, "{}", first_item).unwrap();
18 }
19
20 for item in self {
21 out.push_str(sep);
22 write!(out, "{}", item).unwrap();
23 }
24
25 out
26 }
27}