TagConvertor

Trait TagConvertor 

Source
pub trait TagConvertor<'a> {
    type Color;
    type Modifier;
    type Custom;

    // Required methods
    fn parse_color(&mut self, s: &str) -> Option<Self::Color>;
    fn parse_modifier(&mut self, s: &str) -> Option<Self::Modifier>;
    fn parse_custom_tag(&mut self, s: &str) -> Option<Self::Custom>;

    // Provided methods
    fn parse_built_in_tag(&mut self, s: &str) -> Option<Tag<'a, Self>> { ... }
    fn convert_tag(&mut self, s: &'a str) -> Option<Tag<'a, Self>> { ... }
    fn convert_item(&mut self, item: Item<'a>) -> ItemC<'a, Self> { ... }
    fn convert_line(&mut self, items: Vec<Item<'a>>) -> Vec<ItemC<'a, Self>>  { ... }
    fn convert_ast(
        &mut self,
        ast: Vec<Vec<Item<'a>>>,
    ) -> Vec<Vec<ItemC<'a, Self>>> { ... }
}
Expand description

Trait for convert a raw tag string to Tag type.

Each generator has it own tag convertor, because different backend(show the final output) supports different kind of tags.

This Trait has three assoc type:

  • Color: for foreground or background color
  • Modifier: for style modifier(like bold, italic, etc.)
  • Custom: for custom tag

The Generator with this convertor C will received a series of Item<Tag<C>>, and convert it into final output.

Required Associated Types§

Source

type Color

Color type for foreground and background typed tag.

Source

type Modifier

Modifier type for modifier typed tag.

Source

type Custom

Custom tag type. Usually is the final type represent a style, can be converted from Color and Modifier.

Required Methods§

Source

fn parse_color(&mut self, s: &str) -> Option<Self::Color>

Parse string to color type.

Source

fn parse_modifier(&mut self, s: &str) -> Option<Self::Modifier>

Parse string to modifier type.

Source

fn parse_custom_tag(&mut self, s: &str) -> Option<Self::Custom>

Parse string to custom type.

Only if this call fails, a convertor try to parse the raw tag string to a built-in tag. So the custom tag always have higher priority.

Provided Methods§

Source

fn parse_built_in_tag(&mut self, s: &str) -> Option<Tag<'a, Self>>

Parse string to a builtin tag type.

Source

fn convert_tag(&mut self, s: &'a str) -> Option<Tag<'a, Self>>

convert the tag string to Tag type

Source

fn convert_item(&mut self, item: Item<'a>) -> ItemC<'a, Self>

Convert item with raw tag string to item with Tag type.

It will filtered out all tags that fail to parse.

Source

fn convert_line(&mut self, items: Vec<Item<'a>>) -> Vec<ItemC<'a, Self>>

Convert a line of items with raw tag string to items with Tag type.

It will filtered out all tags that fail to parse.

Source

fn convert_ast(&mut self, ast: Vec<Vec<Item<'a>>>) -> Vec<Vec<ItemC<'a, Self>>>

Convert all item with raw tag string of a ast into items with Tag type.

It will filtered out all tags that fail to parse.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, P> TagConvertor<'a> for ANSITermTagConvertor<P>
where P: CustomTagParser<Output = Style>,

Available on crate feature ansi only.
Source§

impl<'a, P> TagConvertor<'a> for CrosstermTagConvertor<P>
where P: CustomTagParser<Output = ContentStyle>,

Available on crate feature crossterm only.
Source§

impl<'a, P> TagConvertor<'a> for RatatuiTagConvertor<P>
where P: CustomTagParser<Output = Style>,

Available on crate feature ratatui only.