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

    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>;

    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>, and convert it into final output.

Required Associated Types

Color type for foreground and background typed tag.

Modifier type for modifier typed tag.

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

Required Methods

Parse string to color type.

Parse string to modifier type.

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

Parse string to a builtin tag type.

convert the tag string to Tag type

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

It will filtered out all tags that fail to parse.

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

It will filtered out all tags that fail to parse.

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.

Implementors