2023-03-23 21:51:49 +00:00
|
|
|
use super::element::Element;
|
|
|
|
use super::source::Source;
|
2022-10-15 00:17:48 +00:00
|
|
|
|
2023-03-23 21:51:49 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Document<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub zeroth_section: Option<Section<'s>>,
|
|
|
|
pub children: Vec<Heading<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Heading<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub children: Vec<DocumentElement<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Section<'s> {
|
|
|
|
pub source: &'s str,
|
|
|
|
pub children: Vec<Element<'s>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum DocumentElement<'s> {
|
|
|
|
Heading(Heading<'s>),
|
|
|
|
Section(Section<'s>),
|
|
|
|
}
|
2022-12-04 03:44:53 +00:00
|
|
|
|
2023-03-23 21:51:49 +00:00
|
|
|
impl<'s> Source<'s> for Document<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
self.source
|
|
|
|
}
|
|
|
|
}
|
2022-12-18 09:22:28 +00:00
|
|
|
|
2023-03-23 21:51:49 +00:00
|
|
|
impl<'s> Source<'s> for DocumentElement<'s> {
|
|
|
|
fn get_source(&'s self) -> &'s str {
|
|
|
|
match self {
|
|
|
|
DocumentElement::Heading(obj) => obj.source,
|
|
|
|
DocumentElement::Section(obj) => obj.source,
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 00:14:19 +00:00
|
|
|
}
|