stylic 0.3.1

A simple, fast library for styling text with ANSI escape codes
Documentation
use core::fmt;

/// Format a string lazily.
///
/// This is cheap, like [`format_args`], but doesn't cause temporary lifetime issues, allowing
/// it to be easily used in let bindings.
/// See <https://github.com/rust-lang/rust/issues/92698> for more information about this.
///
/// This works by storing a callback that will be invoked when [`Display::fmt`](fmt::Display::fmt)
/// is called. As such, format arguments may be evaluated multiple times.
#[macro_export]
macro_rules! lazy_format {
    ($($tt:tt)+) => {
        $crate::macros::LazyFormat::new(|f| write!(f, $($tt)+))
    };
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct LazyFormat<F>(F);

impl<F: Fn(&mut fmt::Formatter) -> fmt::Result> LazyFormat<F> {
    #[inline]
    pub fn new(callback: F) -> Self {
        Self(callback)
    }
}

impl<F: Fn(&mut fmt::Formatter) -> fmt::Result> fmt::Display for LazyFormat<F> {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        (self.0)(f)
    }
}