diff options
| author | Phil Schaf | 2015-11-14 21:18:04 +0100 | 
|---|---|---|
| committer | Phil Schaf | 2015-11-14 21:18:04 +0100 | 
| commit | 1434756b2b6cedb3d56528ca1802a92be4eaba56 (patch) | |
| tree | 84a30e24279f2dda29fc4a7677ca6b79d40b04e6 /src/document_tree | |
| parent | 5fdb21df228c78061cce9ee910fa87da0fd99d46 (diff) | |
| download | rust-rst-1434756b2b6cedb3d56528ca1802a92be4eaba56.tar.bz2 | |
improved HasChildren trait
Diffstat (limited to 'src/document_tree')
| -rw-r--r-- | src/document_tree/element_categories.rs | 7 | ||||
| -rw-r--r-- | src/document_tree/element_types.rs | 2 | ||||
| -rw-r--r-- | src/document_tree/elements.rs | 23 | ||||
| -rw-r--r-- | src/document_tree/mod.rs | 10 | 
4 files changed, 20 insertions, 22 deletions
| diff --git a/src/document_tree/element_categories.rs b/src/document_tree/element_categories.rs index 5f12cc6..9ea79e6 100644 --- a/src/document_tree/element_categories.rs +++ b/src/document_tree/element_categories.rs @@ -1,7 +1,10 @@  use super::elements::*;  pub trait HasChildren<C> { -	fn add_child<R: Into<C>>(&mut self, R); +	fn children(&mut self) -> &mut Vec<C>; +	fn append_child<R: Into<C>>(&mut self, child: R) { +		self.children().push(child.into()); +	}  }  macro_rules! synonymous_enum {( $name:ident { $( $entry:ident ),* } ) => ( @@ -55,5 +58,5 @@ synonymous_enum!(SubOptionListItem { OptionGroup, Description });  synonymous_enum!(SubOption { OptionString, OptionArgument });  synonymous_enum!(SubLineBlock { LineBlock, Line });  synonymous_enum!(SubBlockQuote { Attribution, BodyElement }); -synonymous_enum!(SubFootnote { Label_, BodyElement }); +synonymous_enum!(SubFootnote { Label, BodyElement });  synonymous_enum!(SubFigure { Image, Caption, Legend, BodyElement }); diff --git a/src/document_tree/element_types.rs b/src/document_tree/element_types.rs index 232d44f..9ac90e2 100644 --- a/src/document_tree/element_types.rs +++ b/src/document_tree/element_types.rs @@ -62,7 +62,7 @@  // 	OptionListItem, OptionGroup, Description, Option_, OptionString,  // 	OptionArgument { delimiter: String },  // -// 	Line, Attribution, Label_, +// 	Line, Attribution, Label,  //  // 	Caption, Legend,  // 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 diff --git a/src/document_tree/mod.rs b/src/document_tree/mod.rs index 868b9f8..35f2540 100644 --- a/src/document_tree/mod.rs +++ b/src/document_tree/mod.rs @@ -6,16 +6,6 @@ pub mod element_categories;  pub mod extra_attributes;  pub mod attribute_types; -use self::element_categories::StructuralSubElement; -  pub use self::elements::*; //Element,CommonAttributes,  pub use self::extra_attributes::ExtraAttributes;  pub use self::element_categories::HasChildren; - -#[derive(Default,Debug)] -pub struct Document { children: Vec<Box<StructuralSubElement>> } -impl HasChildren<StructuralSubElement> for Document { -	fn add_child<R: Into<StructuralSubElement>>(&mut self, child: R) { -		self.children.push(Box::new(child.into())); -	} -} | 
