Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style new const #60

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct Style {
/// Whether this style is hidden.
pub is_hidden: bool,

/// Whether this style is struckthrough.
/// Whether this style is strikethrough.
pub is_strikethrough: bool,

/// Wether this style is always displayed starting with a reset code to clear any remaining style artifacts
Expand All @@ -60,8 +60,20 @@ impl Style {
/// let style = Style::new();
/// println!("{}", style.paint("hi"));
/// ```
pub fn new() -> Style {
Style::default()
pub const fn new() -> Style {
Style {
foreground: None,
background: None,
is_bold: false,
is_dimmed: false,
is_italic: false,
is_underline: false,
is_blink: false,
is_reverse: false,
is_hidden: false,
is_strikethrough: false,
prefix_with_reset: false,
}
}

/// Returns a [`Style`] with the `Style.prefix_with_reset` property set.
Expand Down Expand Up @@ -262,7 +274,7 @@ impl Style {
/// assert_eq!(false, Style::default().bold().is_plain());
/// ```
pub fn is_plain(self) -> bool {
self == Style::default()
self == Style::new()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot constify this method since the equal operand is not usable in const context

}
}

Expand All @@ -278,19 +290,7 @@ impl Default for Style {
/// assert_eq!("txt", Style::default().paint("txt").to_string());
/// ```
fn default() -> Style {
Style {
foreground: None,
background: None,
is_bold: false,
is_dimmed: false,
is_italic: false,
is_underline: false,
is_blink: false,
is_reverse: false,
is_hidden: false,
is_strikethrough: false,
prefix_with_reset: false,
}
Style::new()
}
}

Expand Down
Loading