use std::fmt;
#[derive(Copy, Clone, Debug)]
#[repr(transparent)]
pub struct CommaFmt<T>(pub T);
impl<T: fmt::Display, U: fmt::Display> fmt::Display for CommaFmt<(T, U)> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(format_args!("{},{}", (self.0).0, (self.0).1))
}
}
impl<T: fmt::Display, U: fmt::Display, V: fmt::Display> fmt::Display for CommaFmt<(T, U, V)> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(format_args!("{},{},{}", (self.0).0, (self.0).1, (self.0).2))
}
}
impl<T: fmt::Display> fmt::Display for CommaFmt<[T; 2]> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(format_args!("{},{}", (self.0)[0], (self.0)[1]))
}
}
impl<T: fmt::Display> fmt::Display for CommaFmt<[T; 3]> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(format_args!("{},{},{}", (self.0)[0], (self.0)[1], (self.0)[2]))
}
}
#[derive(Copy, Clone, Debug)]
#[repr(transparent)]
pub struct SpacedSet<I>(pub I);
impl<T: fmt::Display, I: Clone + IntoIterator<Item = T>> fmt::Display for SpacedSet<I> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for item in self.0.clone() {
f.write_fmt(format_args!("{} ", item))?;
}
Ok(())
}
}
pub fn spaced_comma_set<I: IntoIterator>(iterable: I) -> SpacedSet<impl Clone + Iterator<Item = CommaFmt<I::Item>>> where I::IntoIter: Clone {
SpacedSet(iterable.into_iter().map(CommaFmt))
}