#[derive(Debug)] pub enum Token<'a> { TextElement(TextElement<'a>), Paragraph(Paragraph<'a>), } impl<'a> Into> for TextElement<'a> { fn into(self) -> Token<'a> { Token::TextElement(self) } } impl<'a> Into> for Paragraph<'a> { fn into(self) -> Token<'a> { Token::Paragraph(self) } } #[derive(Debug)] pub enum TextElement<'a> { Span(Span<'a>), Space(Space<'a>), LineBreak(LineBreak<'a>), Symbol(Symbol<'a>), Bold(Bold<'a>), Link(Link<'a>), } #[derive(Debug)] pub struct Span<'a> { pub source: &'a str, } #[derive(Debug)] pub struct Space<'a> { pub source: &'a str, } #[derive(Debug)] pub struct LineBreak<'a> { pub source: &'a str, } #[derive(Debug)] pub struct Symbol<'a> { pub source: &'a str, } #[derive(Debug)] pub struct BlankLine<'a> { pub source: &'a str, } #[derive(Debug)] pub struct Sequence<'a> { pub source: &'a str, } #[derive(Debug)] pub struct Bold<'a> { pub source: &'a str, } #[derive(Debug)] pub struct Link<'a> { pub source: &'a str, } #[derive(Debug)] pub struct Paragraph<'a> { pub source: &'a str, pub contents: Vec>, pub paragraph_end: &'a str, } pub trait Source<'a> { fn get_source(&'a self) -> &'a str; } impl<'a> Source<'a> for TextElement<'a> { fn get_source(&'a self) -> &'a str { match self { TextElement::Span(elem) => elem.source, TextElement::Space(elem) => elem.source, TextElement::LineBreak(elem) => elem.source, TextElement::Symbol(elem) => elem.source, TextElement::Bold(elem) => elem.source, TextElement::Link(elem) => elem.source, } } } impl<'a> Source<'a> for Paragraph<'a> { fn get_source(&'a self) -> &'a str { self.source } } #[derive(Debug)] pub struct PlainList<'a> { pub source: &'a str, } impl<'a> Source<'a> for PlainList<'a> { fn get_source(&'a self) -> &'a str { self.source } } #[derive(Debug)] pub struct ListItem<'a> { pub source: &'a str, pub bullet: &'a str, pub counter_set: &'a str, pub check_box: &'a str, pub item_tag: &'a str, pub contents: Vec>, } impl<'a> Source<'a> for ListItem<'a> { fn get_source(&'a self) -> &'a str { self.source } } #[derive(Debug)] pub struct ListCounter<'a> { pub source: &'a str, } impl<'a> Source<'a> for ListCounter<'a> { fn get_source(&'a self) -> &'a str { self.source } }