1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use std::fmt::{self, Display, Formatter};
use super::{ContentStyle, PrintStyledContent};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct StyledContent<D: Display> {
style: ContentStyle,
content: D,
}
impl<D: Display> StyledContent<D> {
#[inline]
pub fn new(style: ContentStyle, content: D) -> StyledContent<D> {
StyledContent { style, content }
}
#[inline]
pub fn content(&self) -> &D {
&self.content
}
#[inline]
pub fn style(&self) -> &ContentStyle {
&self.style
}
#[inline]
pub fn style_mut(&mut self) -> &mut ContentStyle {
&mut self.style
}
}
impl<D: Display> AsRef<ContentStyle> for StyledContent<D> {
fn as_ref(&self) -> &ContentStyle {
&self.style
}
}
impl<D: Display> AsMut<ContentStyle> for StyledContent<D> {
fn as_mut(&mut self) -> &mut ContentStyle {
&mut self.style
}
}
impl<D: Display> Display for StyledContent<D> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
crate::command::execute_fmt(
f,
PrintStyledContent(StyledContent {
style: self.style,
content: &self.content,
}),
)
}
}