diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/anstyle/src/color.rs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/anstyle/src/color.rs')
-rw-r--r-- | vendor/anstyle/src/color.rs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/vendor/anstyle/src/color.rs b/vendor/anstyle/src/color.rs index cbf0b47a2..8dcf6ca5b 100644 --- a/vendor/anstyle/src/color.rs +++ b/vendor/anstyle/src/color.rs @@ -17,13 +17,13 @@ impl Color { /// Create a [`Style`][crate::Style] with this as the foreground #[inline] - pub fn on_default(self) -> crate::Style { + pub const fn on_default(self) -> crate::Style { crate::Style::new().fg_color(Some(self)) } /// Render the ANSI code for a foreground color #[inline] - pub fn render_fg(self) -> impl core::fmt::Display { + pub fn render_fg(self) -> impl core::fmt::Display + Copy + Clone { match self { Self::Ansi(color) => DisplayBuffer::default().write_str(color.as_fg_str()), Self::Ansi256(color) => color.as_fg_buffer(), @@ -44,7 +44,7 @@ impl Color { /// Render the ANSI code for a background color #[inline] - pub fn render_bg(self) -> impl core::fmt::Display { + pub fn render_bg(self) -> impl core::fmt::Display + Copy + Clone { match self { Self::Ansi(color) => DisplayBuffer::default().write_str(color.as_bg_str()), Self::Ansi256(color) => color.as_bg_buffer(), @@ -64,7 +64,7 @@ impl Color { } #[inline] - pub(crate) fn render_underline(self) -> impl core::fmt::Display { + pub(crate) fn render_underline(self) -> impl core::fmt::Display + Copy + Clone { match self { Self::Ansi(color) => color.as_underline_buffer(), Self::Ansi256(color) => color.as_underline_buffer(), @@ -185,13 +185,13 @@ impl AnsiColor { /// Create a [`Style`][crate::Style] with this as the foreground #[inline] - pub fn on_default(self) -> crate::Style { - crate::Style::new().fg_color(Some(self.into())) + pub const fn on_default(self) -> crate::Style { + crate::Style::new().fg_color(Some(Color::Ansi(self))) } /// Render the ANSI code for a foreground color #[inline] - pub fn render_fg(self) -> impl core::fmt::Display { + pub fn render_fg(self) -> impl core::fmt::Display + Copy + Clone { self.as_fg_str() } @@ -219,7 +219,7 @@ impl AnsiColor { /// Render the ANSI code for a background color #[inline] - pub fn render_bg(self) -> impl core::fmt::Display { + pub fn render_bg(self) -> impl core::fmt::Display + Copy + Clone { self.as_bg_str() } @@ -340,8 +340,8 @@ impl Ansi256Color { /// Create a [`Style`][crate::Style] with this as the foreground #[inline] - pub fn on_default(self) -> crate::Style { - crate::Style::new().fg_color(Some(self.into())) + pub const fn on_default(self) -> crate::Style { + crate::Style::new().fg_color(Some(Color::Ansi256(self))) } #[inline] @@ -396,7 +396,7 @@ impl Ansi256Color { /// Render the ANSI code for a foreground color #[inline] - pub fn render_fg(self) -> impl core::fmt::Display { + pub fn render_fg(self) -> impl core::fmt::Display + Copy + Clone { self.as_fg_buffer() } @@ -410,7 +410,7 @@ impl Ansi256Color { /// Render the ANSI code for a background color #[inline] - pub fn render_bg(self) -> impl core::fmt::Display { + pub fn render_bg(self) -> impl core::fmt::Display + Copy + Clone { self.as_bg_buffer() } @@ -460,8 +460,8 @@ impl RgbColor { /// Create a [`Style`][crate::Style] with this as the foreground #[inline] - pub fn on_default(self) -> crate::Style { - crate::Style::new().fg_color(Some(self.into())) + pub const fn on_default(self) -> crate::Style { + crate::Style::new().fg_color(Some(Color::Rgb(self))) } #[inline] @@ -481,7 +481,7 @@ impl RgbColor { /// Render the ANSI code for a foreground color #[inline] - pub fn render_fg(self) -> impl core::fmt::Display { + pub fn render_fg(self) -> impl core::fmt::Display + Copy + Clone { self.as_fg_buffer() } @@ -499,7 +499,7 @@ impl RgbColor { /// Render the ANSI code for a background color #[inline] - pub fn render_bg(self) -> impl core::fmt::Display { + pub fn render_bg(self) -> impl core::fmt::Display + Copy + Clone { self.as_bg_buffer() } @@ -536,7 +536,7 @@ impl From<(u8, u8, u8)> for RgbColor { } } -#[derive(Default, Debug)] +#[derive(Copy, Clone, Default, Debug)] struct DisplayBuffer { buffer: [u8; 19], len: usize, @@ -598,6 +598,7 @@ impl core::fmt::Display for DisplayBuffer { } #[cfg(test)] +#[cfg(feature = "std")] mod test { use super::*; |