use std::fmt;
pub struct DisplaySlice<'a, T>(pub &'a [T]);
impl<T: fmt::Display> fmt::Display for DisplaySlice<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
DisplayIter(self.0.iter()).fmt(f)
}
}
pub struct DisplayIter<I>(pub I);
impl<I> fmt::Display for DisplayIter<I>
where
I: Iterator + Clone,
I::Item: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut first = true;
write!(f, "[")?;
for item in self.0.clone() {
if !first {
write!(f, ", ")?;
}
first = false;
write!(f, "{item}")?;
}
write!(f, "]")
}
}
pub struct DebugIter<I>(pub I);
impl<I> fmt::Display for DebugIter<I>
where
I: Iterator + Clone,
I::Item: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut first = true;
write!(f, "[")?;
for item in self.0.clone() {
if !first {
write!(f, ", ")?;
}
first = false;
write!(f, "{item:?}")?;
}
write!(f, "]")
}
}
pub struct DisplayOption<T>(pub Option<T>);
impl<T: fmt::Display> fmt::Display for DisplayOption<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.0 {
Some(value) => write!(f, "{value}"),
None => write!(f, "(none)"),
}
}
}