Skip to content

Commit 34636cf

Browse files
authored
fix: const fn for ContentStyle and StyledContent (#1027)
1 parent f598b10 commit 34636cf

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/style/content_style.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@ pub struct ContentStyle {
1818
}
1919

2020
impl ContentStyle {
21-
/// Creates a `StyledContent` by applying the style to the given `val`.
21+
/// Creates a [`StyledContent`] by applying the style to the given `val`.
2222
#[inline]
23-
pub fn apply<D: Display>(self, val: D) -> StyledContent<D> {
23+
pub const fn apply<D: Display>(self, val: D) -> StyledContent<D> {
2424
StyledContent::new(self, val)
2525
}
2626

27-
/// Creates a new `ContentStyle`.
27+
/// Creates a new [`ContentStyle`].
2828
#[inline]
29-
pub fn new() -> ContentStyle {
30-
ContentStyle::default()
29+
pub const fn new() -> ContentStyle {
30+
Self {
31+
foreground_color: None,
32+
background_color: None,
33+
underline_color: None,
34+
attributes: Attributes::none(),
35+
}
3136
}
3237
}
3338

src/style/styled_content.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,28 @@ pub struct StyledContent<D: Display> {
2727
}
2828

2929
impl<D: Display> StyledContent<D> {
30-
/// Creates a new `StyledContent`.
30+
/// Creates a new [`StyledContent`].
3131
#[inline]
32-
pub fn new(style: ContentStyle, content: D) -> StyledContent<D> {
32+
pub const fn new(style: ContentStyle, content: D) -> StyledContent<D> {
3333
StyledContent { style, content }
3434
}
3535

3636
/// Returns the content.
3737
#[inline]
38-
pub fn content(&self) -> &D {
38+
pub const fn content(&self) -> &D {
3939
&self.content
4040
}
4141

4242
/// Returns the style.
4343
#[inline]
44-
pub fn style(&self) -> &ContentStyle {
44+
pub const fn style(&self) -> &ContentStyle {
4545
&self.style
4646
}
4747

4848
/// Returns a mutable reference to the style, so that it can be further
4949
/// manipulated
5050
#[inline]
51-
pub fn style_mut(&mut self) -> &mut ContentStyle {
51+
pub const fn style_mut(&mut self) -> &mut ContentStyle {
5252
&mut self.style
5353
}
5454
}

0 commit comments

Comments
 (0)