2023-03-23 21:51:49 +00:00
|
|
|
use super::source::Source;
|
2023-03-23 21:02:08 +00:00
|
|
|
|
2023-03-23 21:26:07 +00:00
|
|
|
#[derive(Debug)]
|
2023-03-23 20:49:52 +00:00
|
|
|
pub enum Object<'s> {
|
2023-04-23 00:22:07 +00:00
|
|
|
Bold(Bold<'s>),
|
|
|
|
Italic(Italic<'s>),
|
|
|
|
Underline(Underline<'s>),
|
|
|
|
StrikeThrough(StrikeThrough<'s>),
|
|
|
|
Code(Code<'s>),
|
|
|
|
Verbatim(Verbatim<'s>),
|
2023-04-03 19:15:16 +00:00
|
|
|
|
2023-03-23 20:49:52 +00:00
|
|
|
PlainText(PlainText<'s>),
|
2023-04-03 19:15:16 +00:00
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2023-03-23 21:02:08 +00:00
|
|
|
RegularLink(RegularLink<'s>),
|
2023-03-23 20:49:52 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 21:26:07 +00:00
|
|
|
#[derive(Debug)]
|
2023-04-23 00:22:07 +00:00
|
|
|
pub struct Bold<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub children: Vec<Object<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Italic<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub children: Vec<Object<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Underline<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub children: Vec<Object<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct StrikeThrough<'s> {
|
2023-03-23 20:49:52 +00:00
|
|
|
pub source: &'s str,
|
2023-04-22 23:34:13 +00:00
|
|
|
pub children: Vec<Object<'s>>,
|
2023-03-23 20:49:52 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 00:22:07 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Code<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub contents: &'s str,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Verbatim<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub contents: &'s str,
|
|
|
|
}
|
|
|
|
|
2023-03-23 21:26:07 +00:00
|
|
|
#[derive(Debug)]
|
2023-03-23 20:49:52 +00:00
|
|
|
pub struct PlainText<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
}
|
|
|
|
|
2023-03-23 21:26:07 +00:00
|
|
|
#[derive(Debug)]
|
2023-03-23 21:02:08 +00:00
|
|
|
pub struct RegularLink<'s> {
|
|
|
|
pub source: &'s str,
|
2023-03-23 20:49:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'s> Source<'s> for Object<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
match self {
|
2023-04-23 00:22:07 +00:00
|
|
|
Object::Bold(obj) => obj.source,
|
|
|
|
Object::Italic(obj) => obj.source,
|
|
|
|
Object::Underline(obj) => obj.source,
|
|
|
|
Object::StrikeThrough(obj) => obj.source,
|
|
|
|
Object::Code(obj) => obj.source,
|
|
|
|
Object::Verbatim(obj) => obj.source,
|
2023-03-23 20:49:52 +00:00
|
|
|
Object::PlainText(obj) => obj.source,
|
2023-03-23 21:02:08 +00:00
|
|
|
Object::RegularLink(obj) => obj.source,
|
2023-03-23 20:49:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-23 00:48:01 +00:00
|
|
|
|
|
|
|
impl<'s> Source<'s> for Bold<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'s> Source<'s> for Italic<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'s> Source<'s> for Underline<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'s> Source<'s> for StrikeThrough<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'s> Source<'s> for Code<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'s> Source<'s> for Verbatim<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|