aboutsummaryrefslogtreecommitdiffstats
path: root/src/document_tree/elements.rs
diff options
context:
space:
mode:
authorPhil Schaf2015-11-14 21:18:04 +0100
committerPhil Schaf2015-11-14 21:18:04 +0100
commit1434756b2b6cedb3d56528ca1802a92be4eaba56 (patch)
tree84a30e24279f2dda29fc4a7677ca6b79d40b04e6 /src/document_tree/elements.rs
parent5fdb21df228c78061cce9ee910fa87da0fd99d46 (diff)
downloadrust-rst-1434756b2b6cedb3d56528ca1802a92be4eaba56.tar.bz2
improved HasChildren trait
Diffstat (limited to 'src/document_tree/elements.rs')
-rw-r--r--src/document_tree/elements.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs
index e6709b4..0859151 100644
--- a/src/document_tree/elements.rs
+++ b/src/document_tree/elements.rs
@@ -39,8 +39,8 @@ macro_rules! impl_element(($name:ident) => {
macro_rules! impl_children(($name:ident, $childtype:ident) => {
impl HasChildren<$childtype> for $name {
- fn add_child<R: Into<$childtype>>(&mut self, child: R) {
- self.children.push(Box::new(child.into()));
+ fn children(&mut self) -> &mut Vec<$childtype> {
+ &mut self.children
}
}
});
@@ -69,12 +69,12 @@ macro_rules! impl_elem(
};
($name:ident, $childtype:ident) => {
#[derive(Default,Debug)]
- pub struct $name { common: CommonAttributes, children: Vec<Box<$childtype>> }
+ pub struct $name { common: CommonAttributes, children: Vec<$childtype> }
impl_element!($name); impl_children!($name, $childtype);
};
($name:ident, $childtype:ident; +) => {
#[derive(Default,Debug)]
- pub struct $name { common: CommonAttributes, extra: extra_attributes::$name, children: Vec<Box<$childtype>> }
+ pub struct $name { common: CommonAttributes, extra: extra_attributes::$name, children: Vec<$childtype> }
impl_element!($name); impl_extra!($name); impl_children!($name, $childtype);
};
);
@@ -83,6 +83,11 @@ macro_rules! impl_elems(( $( ($($args:tt)*) )* ) => {
$( impl_elem!($($args)*); )*
});
+
+#[derive(Default,Debug)]
+pub struct Document { children: Vec<StructuralSubElement> }
+impl_children!(Document, StructuralSubElement);
+
impl_elems!(
//structual elements
(Section, SubSection)
@@ -123,8 +128,8 @@ impl_elems!(
(Comment, TextOrInlineElement; +)
(Pending)
(Target; +)
- (Raw; +)
- (Image; *)
+ (Raw; +)
+ (Image; *)
//compound body elements
(Compound, BodyElement)
@@ -151,7 +156,7 @@ impl_elems!(
(Footnote, SubFootnote; +)
(Citation, SubFootnote; +)
(SystemMessage, BodyElement; +)
- (Figure, SubFigure; +)
+ (Figure, SubFigure; +)
(Table; +) //TODO
//body sub elements
@@ -174,7 +179,7 @@ impl_elems!(
(Line, TextOrInlineElement)
(Attribution, TextOrInlineElement)
- (Label_, TextOrInlineElement)
+ (Label, TextOrInlineElement)
(Caption, TextOrInlineElement)
(Legend, BodyElement)
@@ -199,7 +204,7 @@ impl_elems!(
//also have non-inline versions. Inline image is no figure child, inline target has content
(TargetInline, TextOrInlineElement; +)
- (RawInline; +)
+ (RawInline; +)
(ImageInline; *)
//text element