From ddb4a0c29c30edba0f9727731ef11fa870b4ccf7 Mon Sep 17 00:00:00 2001 From: Property404 Date: Sat, 23 Apr 2022 10:06:30 -0400 Subject: [PATCH] Make ColorSpec constructor and getters const --- src/lib.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c93cf7b..296b53d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1590,6 +1590,13 @@ pub struct ColorSpec { impl Default for ColorSpec { fn default() -> ColorSpec { + ColorSpec::new() + } +} + +impl ColorSpec { + /// Create a new color specification that has no colors or styles. + pub const fn new() -> ColorSpec { ColorSpec { fg_color: None, bg_color: None, @@ -1601,15 +1608,9 @@ impl Default for ColorSpec { reset: true, } } -} - -impl ColorSpec { - /// Create a new color specification that has no colors or styles. - pub fn new() -> ColorSpec { - ColorSpec::default() - } /// Get the foreground color. + // TODO: Make this const when MSVR is 1.48 pub fn fg(&self) -> Option<&Color> { self.fg_color.as_ref() } @@ -1621,6 +1622,7 @@ impl ColorSpec { } /// Get the background color. + // TODO: Make this const when MSVR is 1.48 pub fn bg(&self) -> Option<&Color> { self.bg_color.as_ref() } @@ -1634,7 +1636,7 @@ impl ColorSpec { /// Get whether this is bold or not. /// /// Note that the bold setting has no effect in a Windows console. - pub fn bold(&self) -> bool { + pub const fn bold(&self) -> bool { self.bold } @@ -1649,7 +1651,7 @@ impl ColorSpec { /// Get whether this is dimmed or not. /// /// Note that the dimmed setting has no effect in a Windows console. - pub fn dimmed(&self) -> bool { + pub const fn dimmed(&self) -> bool { self.dimmed } @@ -1664,7 +1666,7 @@ impl ColorSpec { /// Get whether this is italic or not. /// /// Note that the italic setting has no effect in a Windows console. - pub fn italic(&self) -> bool { + pub const fn italic(&self) -> bool { self.italic } @@ -1679,7 +1681,7 @@ impl ColorSpec { /// Get whether this is underline or not. /// /// Note that the underline setting has no effect in a Windows console. - pub fn underline(&self) -> bool { + pub const fn underline(&self) -> bool { self.underline } @@ -1698,7 +1700,7 @@ impl ColorSpec { /// settings are applied. /// /// Note that the reset setting has no effect in a Windows console. - pub fn reset(&self) -> bool { + pub const fn reset(&self) -> bool { self.reset } @@ -1726,7 +1728,7 @@ impl ColorSpec { /// /// On Windows systems, this will output the ANSI escape sequence /// that will print a brighter version of the color specified. - pub fn intense(&self) -> bool { + pub const fn intense(&self) -> bool { self.intense }