fluent_ansi/
styling_element.rs

1/// An element that can be composed with any [styling type](crate#styling-types).
2///
3/// This trait is used to define elements that can be added to a `Style`. Such elements
4/// include effects ([`Effect`](crate::Effect)) and colors (like [`TargetedColor`](crate::TargetedColor)).
5pub trait StylingElement<S> {
6    /// Adds this element to the given parameter, returning it updated.
7    #[must_use]
8    fn add_to(self, style_set: S) -> S;
9}
10
11macro_rules! impl_styling_element_for {
12    {$type:ty {
13        args: [$self:ident, $composed_styling:ident];
14        add_to: $add_to:block
15    }} => {
16        impl $crate::StylingElement<$crate::Style> for $type {
17            fn add_to($self, $composed_styling: $crate::Style) -> $crate::Style {
18                $add_to
19            }
20        }
21
22        impl<C: core::fmt::Display> $crate::StylingElement<$crate::Styled<C>> for $type {
23            fn add_to($self, $composed_styling: $crate::Styled<C>) -> $crate::Styled<C> {
24                $add_to
25            }
26        }
27    };
28}
29pub(crate) use impl_styling_element_for;