cubob/
pair.rs

1use core::fmt::Display;
2
3/// Trait used to generalize over tuples of displayable types
4/// and references onto such tuples.
5/// Trait is not sealed and can be implementd for any other needed type.
6#[cfg_attr(docsrs, doc(cfg(feature = "struct")))]
7pub trait DisplayPair {
8    /// Type of the left-side variable in corresponding 'left: right' construction.
9    type Left: Display;
10    /// Type of the right-side variable in corresponding 'left: right' construction.
11    type Right: Display;
12
13    /// Return a reference onto the left-side variable in corresponding 'left: right' construction.
14    fn left(&self) -> &Self::Left;
15
16    /// Return a reference onto the right-side variable in corresponding 'left: right' construction.
17    fn rifgt(&self) -> &Self::Right;
18}
19
20impl<L: Display, R: Display> DisplayPair for (L, R) {
21    type Left = L;
22    type Right = R;
23
24    fn left(&self) -> &Self::Left {
25        &self.0
26    }
27
28    fn rifgt(&self) -> &Self::Right {
29        &self.1
30    }
31}
32
33impl<L: Display, R: Display> DisplayPair for &(L, R) {
34    type Left = L;
35    type Right = R;
36
37    fn left(&self) -> &Self::Left {
38        &self.0
39    }
40
41    fn rifgt(&self) -> &Self::Right {
42        &self.1
43    }
44}