use std::fmt;
#[derive(Copy, Clone, Debug)]
pub struct Separated<Sep, Iter>
where
Sep: fmt::Display,
Iter: Copy + IntoIterator,
Iter::Item: fmt::Display,
{
pub sep: Sep,
pub iter: Iter,
}
impl<Sep, Iter> fmt::Display for Separated<Sep, Iter>
where
Sep: fmt::Display,
Iter: Copy + IntoIterator,
Iter::Item: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut it = self.iter.into_iter();
if let Some(x) = it.next() {
write!(f, "{}", x)?;
for y in it {
write!(f, "{}{}", self.sep, y)?;
}
}
Ok(())
}
}
#[derive(Copy, Clone, Debug)]
pub struct Repeated<T>
where
T: fmt::Display,
{
pub value: T,
pub count: usize,
}
impl<T> fmt::Display for Repeated<T>
where
T: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for _ in 0..self.count {
write!(f, "{}", self.value)?
}
Ok(())
}
}