use core::fmt::{Debug, Formatter, Result as FmtResult};
use crate::AnsiColorScheme;
pub trait DebugAnsiColored {
fn fmt_colored(
&self,
f: &mut Formatter<'_>,
color_scheme: &'static AnsiColorScheme,
) -> FmtResult;
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct AnsiColored<T> {
pub value: T,
pub color_scheme: &'static AnsiColorScheme,
}
impl<T> AnsiColored<T> {
#[inline]
pub fn new(value: T, color_scheme: &'static AnsiColorScheme) -> Self {
Self {
value,
color_scheme,
}
}
}
impl<T> Debug for AnsiColored<T>
where
T: DebugAnsiColored,
{
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
DebugAnsiColored::fmt_colored(&self.value, f, self.color_scheme)
}
}
impl<T> DebugAnsiColored for &T
where
T: DebugAnsiColored,
{
#[inline]
fn fmt_colored(
&self,
f: &mut Formatter<'_>,
color_scheme: &'static AnsiColorScheme,
) -> FmtResult {
DebugAnsiColored::fmt_colored(&**self, f, color_scheme)
}
}