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§
Required Methods§
Sourcefn parse_color(&mut self, s: &str) -> Option<Self::Color>
fn parse_color(&mut self, s: &str) -> Option<Self::Color>
Parse string to color type.
Sourcefn parse_modifier(&mut self, s: &str) -> Option<Self::Modifier>
fn parse_modifier(&mut self, s: &str) -> Option<Self::Modifier>
Parse string to modifier type.
Sourcefn parse_custom_tag(&mut self, s: &str) -> Option<Self::Custom>
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§
Sourcefn parse_built_in_tag(&mut self, s: &str) -> Option<Tag<'a, Self>>
fn parse_built_in_tag(&mut self, s: &str) -> Option<Tag<'a, Self>>
Parse string to a builtin tag type.
Sourcefn convert_tag(&mut self, s: &'a str) -> Option<Tag<'a, Self>>
fn convert_tag(&mut self, s: &'a str) -> Option<Tag<'a, Self>>
convert the tag string to Tag type
Sourcefn convert_item(&mut self, item: Item<'a>) -> ItemC<'a, Self>
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.
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.
impl<'a, P> TagConvertor<'a> for ANSITermTagConvertor<P>where
P: CustomTagParser<Output = Style>,
ansi only.Source§impl<'a, P> TagConvertor<'a> for CrosstermTagConvertor<P>where
P: CustomTagParser<Output = ContentStyle>,
Available on crate feature crossterm only.
impl<'a, P> TagConvertor<'a> for CrosstermTagConvertor<P>where
P: CustomTagParser<Output = ContentStyle>,
crossterm only.