use std::fmt; pub trait FlatJoinStrsExt: Sized { /// Join an iterator of iterators `str` with a seperator fn flat_join(self, with: &str) -> String; } pub trait JoinStrsExt: Sized { /// Join an iterator of `str` with a seperator fn join(self, with: &str) -> String; } impl JoinStrsExt for I where I: IntoIterator, T: fmt::Display { /// Join an iterator of `str` with a seperator fn join(self, with: &str) -> String { let mut output = String::new(); let mut first=true; for string in self.into_iter() { if !first { output.push_str(with); } let string = string.to_string(); output.push_str(&string[..]); first=false; } output } } impl FlatJoinStrsExt for I where I: IntoIterator, I2: IntoIterator, T: fmt::Display { fn flat_join(self, with: &str) -> String { let mut output = String::new(); let mut first=true; for string in self.into_iter() { if !first { output.push_str(with); } let string: String = string.into_iter().map(|x| x.to_string()).collect(); output.push_str(&string[..]); first=false; } output } }