1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
pub mod attribute;
mod align;
mod anchor;
mod bibliography;
mod clear_float;
mod clone;
mod container;
mod date;
mod definition_list;
mod element;
mod embed;
mod heading;
mod image;
mod link;
mod list;
mod module;
mod partial;
mod ruby;
mod tab;
mod table;
mod tag;
mod variables;
pub use self::align::*;
pub use self::anchor::*;
pub use self::attribute::AttributeMap;
pub use self::bibliography::*;
pub use self::clear_float::*;
pub use self::container::*;
pub use self::date::Date;
pub use self::definition_list::*;
pub use self::element::*;
pub use self::embed::*;
pub use self::heading::*;
pub use self::image::*;
pub use self::link::*;
pub use self::list::*;
pub use self::module::*;
pub use self::partial::*;
pub use self::ruby::*;
pub use self::tab::*;
pub use self::table::*;
pub use self::tag::*;
pub use self::variables::*;
use self::clone::{elements_lists_to_owned, elements_to_owned};
use crate::parsing::{ParseError, ParseOutcome};
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub struct SyntaxTree<'t> {
pub elements: Vec<Element<'t>>,
pub table_of_contents: Vec<Element<'t>>,
pub footnotes: Vec<Vec<Element<'t>>>,
pub bibliographies: BibliographyList<'t>,
#[serde(default)]
pub wikitext_len: usize,
}
impl<'t> SyntaxTree<'t> {
pub(crate) fn from_element_result(
elements: Vec<Element<'t>>,
errors: Vec<ParseError>,
table_of_contents: Vec<Element<'t>>,
footnotes: Vec<Vec<Element<'t>>>,
bibliographies: BibliographyList<'t>,
wikitext_len: usize,
) -> ParseOutcome<Self> {
let tree = SyntaxTree {
elements,
table_of_contents,
footnotes,
bibliographies,
wikitext_len,
};
ParseOutcome::new(tree, errors)
}
pub fn to_owned(&self) -> SyntaxTree<'static> {
SyntaxTree {
elements: elements_to_owned(&self.elements),
table_of_contents: elements_to_owned(&self.table_of_contents),
footnotes: elements_lists_to_owned(&self.footnotes),
bibliographies: self.bibliographies.to_owned(),
wikitext_len: self.wikitext_len,
}
}
}
#[test]
fn borrowed_to_owned<'a>() {
use std::mem;
let tree_1: SyntaxTree<'a> = SyntaxTree::default();
let tree_2: SyntaxTree<'static> = tree_1.to_owned();
mem::drop(tree_1);
let tree_3: SyntaxTree<'static> = tree_2.clone();
mem::drop(tree_3);
}