1use std::fmt;
2
3pub trait DisplayWith<With: ?Sized> {
4 fn fmt(&self, f: &mut std::fmt::Formatter, with: &With) -> std::fmt::Result;
5 fn display_with<'t, 'w>(&'t self, with: &'w With) -> DisplayWithMixer<'t, 'w, Self, With> {
6 DisplayWithMixer(self, with)
7 }
8}
9
10#[derive(Debug, Copy, Clone)]
11pub struct DisplayWithMixer<'t, 'w, T, With>(&'t T, &'w With)
12where
13 T: DisplayWith<With> + ?Sized,
14 With: ?Sized;
15
16impl<'t, 'w, T, With> fmt::Display for DisplayWithMixer<'t, 'w, T, With>
17where
18 T: DisplayWith<With>,
19{
20 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21 self.0.fmt(f, self.1)
22 }
23}