aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhil Schaf2015-11-14 23:24:56 +0100
committerPhil Schaf2015-11-14 23:24:56 +0100
commit154165495d0db0227d0dc45f368f6dce1123a038 (patch)
tree78ef11b3d0946b5b1a3c98ab3126f3a6a2a6bf15 /src
parent11d453f354c3bfd8f2c2f755c0246f3c2f526179 (diff)
downloadrust-rst-154165495d0db0227d0dc45f368f6dce1123a038.tar.bz2
added some convenience conversions
Diffstat (limited to 'src')
-rw-r--r--src/document_tree/element_categories.rs17
-rw-r--r--src/document_tree/elements.rs25
-rw-r--r--src/document_tree/mod.rs3
3 files changed, 29 insertions, 16 deletions
diff --git a/src/document_tree/element_categories.rs b/src/document_tree/element_categories.rs
index d8024ad..e9d07a6 100644
--- a/src/document_tree/element_categories.rs
+++ b/src/document_tree/element_categories.rs
@@ -1,3 +1,5 @@
+use std::fmt::{self,Debug,Formatter};
+
use super::elements::*;
pub trait HasChildren<C> {
@@ -16,11 +18,16 @@ pub trait HasChildren<C> {
}
macro_rules! synonymous_enum {( $name:ident { $( $entry:ident ),* } ) => (
- #[derive(Debug)]
pub enum $name {
- $(
- $entry($entry),
- )*
+ $( $entry($entry), )*
+ }
+
+ impl Debug for $name {
+ fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
+ match self {
+ $( &$name::$entry(ref inner) => inner.fmt(fmt), )*
+ }
+ }
}
$(
@@ -46,7 +53,7 @@ synonymous_enum!(BodyElement {
synonymous_enum!(BibliographicElement { Author, Authors, Organization, Address, Contact, Version, Revision, Status, Date, Copyright, Field });
synonymous_enum!(TextOrInlineElement {
- TextElement, Emphasis, Strong, Literal, Reference, FootnoteReference, CitationReference, SubstitutionReference, TitleReference, Abbreviation, Acronym, Superscript, Subscript, Inline, Problematic, Generated, Math,
+ String, Emphasis, Strong, Literal, Reference, FootnoteReference, CitationReference, SubstitutionReference, TitleReference, Abbreviation, Acronym, Superscript, Subscript, Inline, Problematic, Generated, Math,
//also have non-inline versions. Inline image is no figure child, inline target has content
TargetInline, RawInline, ImageInline
});
diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs
index f1a9b43..024a25a 100644
--- a/src/document_tree/elements.rs
+++ b/src/document_tree/elements.rs
@@ -130,14 +130,14 @@ impl_elems!(
(Paragraph, TextOrInlineElement)
(LiteralBlock, TextOrInlineElement; +)
(DoctestBlock, TextOrInlineElement; +)
- (MathBlock)
+ (MathBlock, String)
(Rubric, TextOrInlineElement)
(SubstitutionDefinition, TextOrInlineElement; +)
(Comment, TextOrInlineElement; +)
(Pending)
(Target; +)
- (Raw; +)
- (Image; *)
+ (Raw, String; +)
+ (Image; *)
//compound body elements
(Compound, BodyElement)
@@ -182,8 +182,8 @@ impl_elems!(
(OptionGroup, Option_)
(Description, BodyElement)
(Option_, SubOption)
- (OptionString, TextOrInlineElement)
- (OptionArgument, TextOrInlineElement; +)
+ (OptionString, String)
+ (OptionArgument, String; +)
(Line, TextOrInlineElement)
(Attribution, TextOrInlineElement)
@@ -208,13 +208,18 @@ impl_elems!(
(Inline, TextOrInlineElement)
(Problematic, TextOrInlineElement; +)
(Generated, TextOrInlineElement)
- (Math)
+ (Math, String)
//also have non-inline versions. Inline image is no figure child, inline target has content
- (TargetInline, TextOrInlineElement; +)
- (RawInline; +)
+ (TargetInline, String; +)
+ (RawInline, String; +)
(ImageInline; *)
- //text element
- (TextElement)
+ //text element = String
);
+
+impl<'a> From<&'a str> for TextOrInlineElement {
+ fn from(s: &'a str) -> TextOrInlineElement {
+ s.to_owned().into()
+ }
+}
diff --git a/src/document_tree/mod.rs b/src/document_tree/mod.rs
index cb54eb5..a9c4760 100644
--- a/src/document_tree/mod.rs
+++ b/src/document_tree/mod.rs
@@ -16,7 +16,8 @@ fn test() {
use document_tree::HasChildren;
let mut doc = dt::Document::default();
- let title = dt::Title::default();
+ let mut title = dt::Title::default();
+ title.append_child("Hi");
doc.append_child(title);
println!("{:?}", doc);