Debian Codegraph @

debian/rust-vendor/ariadne/src/display.rs

raw
1 use std::fmt::{self, Display};
2
3 #[derive(Copy, Clone, Debug)]
4 pub struct Show<T>(pub T);
5
6 impl<T: Display> Display for Show<Option<T>> {
7 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8 match &self.0 {
9 Some(x) => write!(f, "{}", x),
10 None => Ok(()),
11 }
12 }
13 }
14
15 impl<'a, T, F: Fn(&mut fmt::Formatter, &'a T) -> fmt::Result> Display for Show<(&'a [T], F)> {
16 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17 for x in self.0 .0 {
18 (self.0 .1)(f, x)?;
19 }
20 Ok(())
21 }
22 }
23
24 impl<T: Display> Display for Show<(T, usize)> {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26 for _ in 0..self.0 .1 {
27 write!(f, "{}", self.0 .0)?;
28 }
29 Ok(())
30 }
31 }