diff --git a/crates/anstyle/src/color.rs b/crates/anstyle/src/color.rs index 25355627..8dcf6ca5 100644 --- a/crates/anstyle/src/color.rs +++ b/crates/anstyle/src/color.rs @@ -23,7 +23,7 @@ impl Color { /// 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(), @@ -191,7 +191,7 @@ impl AnsiColor { /// 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() } @@ -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() } @@ -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, diff --git a/crates/anstyle/src/effect.rs b/crates/anstyle/src/effect.rs index d31dafe8..56b3e615 100644 --- a/crates/anstyle/src/effect.rs +++ b/crates/anstyle/src/effect.rs @@ -156,7 +156,7 @@ impl Effects { /// Render the ANSI code #[inline] - pub fn render(self) -> impl core::fmt::Display { + pub fn render(self) -> impl core::fmt::Display + Copy + Clone { EffectsDisplay(self) } @@ -307,6 +307,7 @@ pub(crate) const METADATA: [Metadata; 12] = [ }, ]; +#[derive(Copy, Clone, Default, Debug)] struct EffectsDisplay(Effects); impl core::fmt::Display for EffectsDisplay { diff --git a/crates/anstyle/src/reset.rs b/crates/anstyle/src/reset.rs index 5f5f2b46..c8c21409 100644 --- a/crates/anstyle/src/reset.rs +++ b/crates/anstyle/src/reset.rs @@ -5,11 +5,12 @@ pub struct Reset; impl Reset { /// Render the ANSI code #[inline] - pub fn render(self) -> impl core::fmt::Display { + pub fn render(self) -> impl core::fmt::Display + Copy + Clone { ResetDisplay } } +#[derive(Copy, Clone, Default, Debug)] struct ResetDisplay; impl core::fmt::Display for ResetDisplay { diff --git a/crates/anstyle/src/style.rs b/crates/anstyle/src/style.rs index e0cad29d..f4da242b 100644 --- a/crates/anstyle/src/style.rs +++ b/crates/anstyle/src/style.rs @@ -92,7 +92,7 @@ impl Style { /// Render the ANSI code #[inline] - pub fn render(self) -> impl core::fmt::Display { + pub fn render(self) -> impl core::fmt::Display + Copy + Clone { StyleDisplay(self) } @@ -121,7 +121,7 @@ impl Style { /// /// Unlike [`Reset::render`][crate::Reset::render], this will elide the code if there is nothing to reset. #[inline] - pub fn render_reset(self) -> impl core::fmt::Display { + pub fn render_reset(self) -> impl core::fmt::Display + Copy + Clone { if self != Self::new() { RESET } else { @@ -374,6 +374,7 @@ impl core::cmp::PartialEq for Style { } } +#[derive(Copy, Clone, Default, Debug)] struct StyleDisplay(Style); impl core::fmt::Display for StyleDisplay {