diff --git a/src/style.rs b/src/style.rs index 3058767..3f488bd 100644 --- a/src/style.rs +++ b/src/style.rs @@ -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. @@ -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() } } @@ -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() } } @@ -404,10 +404,10 @@ impl Color { /// let style = Color::Red.normal(); /// println!("{}", style.paint("hi")); /// ``` - pub fn normal(self) -> Style { + pub const fn normal(self) -> Style { Style { foreground: Some(self), - ..Style::default() + ..Style::new() } } @@ -422,11 +422,11 @@ impl Color { /// let style = Color::Green.bold(); /// println!("{}", style.paint("hey")); /// ``` - pub fn bold(self) -> Style { + pub const fn bold(self) -> Style { Style { foreground: Some(self), is_bold: true, - ..Style::default() + ..Style::new() } } @@ -441,11 +441,11 @@ impl Color { /// let style = Color::Yellow.dimmed(); /// println!("{}", style.paint("sup")); /// ``` - pub fn dimmed(self) -> Style { + pub const fn dimmed(self) -> Style { Style { foreground: Some(self), is_dimmed: true, - ..Style::default() + ..Style::new() } } @@ -460,11 +460,11 @@ impl Color { /// let style = Color::Blue.italic(); /// println!("{}", style.paint("greetings")); /// ``` - pub fn italic(self) -> Style { + pub const fn italic(self) -> Style { Style { foreground: Some(self), is_italic: true, - ..Style::default() + ..Style::new() } } @@ -479,11 +479,11 @@ impl Color { /// let style = Color::Purple.underline(); /// println!("{}", style.paint("salutations")); /// ``` - pub fn underline(self) -> Style { + pub const fn underline(self) -> Style { Style { foreground: Some(self), is_underline: true, - ..Style::default() + ..Style::new() } } @@ -498,11 +498,11 @@ impl Color { /// let style = Color::Cyan.blink(); /// println!("{}", style.paint("wazzup")); /// ``` - pub fn blink(self) -> Style { + pub const fn blink(self) -> Style { Style { foreground: Some(self), is_blink: true, - ..Style::default() + ..Style::new() } } @@ -517,11 +517,11 @@ impl Color { /// let style = Color::Black.reverse(); /// println!("{}", style.paint("aloha")); /// ``` - pub fn reverse(self) -> Style { + pub const fn reverse(self) -> Style { Style { foreground: Some(self), is_reverse: true, - ..Style::default() + ..Style::new() } } @@ -536,11 +536,11 @@ impl Color { /// let style = Color::White.hidden(); /// println!("{}", style.paint("ahoy")); /// ``` - pub fn hidden(self) -> Style { + pub const fn hidden(self) -> Style { Style { foreground: Some(self), is_hidden: true, - ..Style::default() + ..Style::new() } } @@ -555,11 +555,11 @@ impl Color { /// let style = Color::Fixed(244).strikethrough(); /// println!("{}", style.paint("yo")); /// ``` - pub fn strikethrough(self) -> Style { + pub const fn strikethrough(self) -> Style { Style { foreground: Some(self), is_strikethrough: true, - ..Style::default() + ..Style::new() } } @@ -574,11 +574,11 @@ impl Color { /// let style = Color::Fixed(244).reset_before_style(); /// println!("{}", style.paint("yo")); /// ``` - pub fn reset_before_style(self) -> Style { + pub const fn reset_before_style(self) -> Style { Style { foreground: Some(self), prefix_with_reset: true, - ..Style::default() + ..Style::new() } } @@ -593,11 +593,11 @@ impl Color { /// let style = Color::Rgb(31, 31, 31).on(Color::White); /// println!("{}", style.paint("eyyyy")); /// ``` - pub fn on(self, background: Color) -> Style { + pub const fn on(self, background: Color) -> Style { Style { foreground: Some(self), background: Some(background), - ..Style::default() + ..Style::new() } } }