1use std::fmt;
2
3pub struct DisplaySlice<'a, T>(pub &'a [T]);
5
6impl<T: fmt::Display> fmt::Display for DisplaySlice<'_, T> {
7 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8 DisplayIter(self.0.iter()).fmt(f)
10 }
11}
12
13pub struct DisplayIter<I>(pub I);
19
20impl<I> fmt::Display for DisplayIter<I>
21where
22 I: Iterator + Clone,
23 I::Item: fmt::Display,
24{
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 let mut first = true;
27 write!(f, "[")?;
28 for item in self.0.clone() {
29 if !first {
30 write!(f, ", ")?;
31 }
32 first = false;
33 write!(f, "{item}")?;
34 }
35 write!(f, "]")
36 }
37}
38
39pub struct DebugIter<I>(pub I);
45
46impl<I> fmt::Display for DebugIter<I>
47where
48 I: Iterator + Clone,
49 I::Item: fmt::Debug,
50{
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 let mut first = true;
53 write!(f, "[")?;
54 for item in self.0.clone() {
55 if !first {
56 write!(f, ", ")?;
57 }
58 first = false;
59 write!(f, "{item:?}")?;
60 }
61 write!(f, "]")
62 }
63}
64
65pub struct DisplayOption<T>(pub Option<T>);
68
69impl<T: fmt::Display> fmt::Display for DisplayOption<T> {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 match &self.0 {
72 Some(value) => write!(f, "{value}"),
73 None => write!(f, "(none)"),
74 }
75 }
76}