aboutsummaryrefslogtreecommitdiffstats
path: root/src/document_tree
diff options
context:
space:
mode:
authorPhilipp A2018-11-22 10:29:15 +0100
committerPhilipp A2018-11-22 10:29:15 +0100
commitbc5af7498160a9072af5a731f5116ef2db1e30b9 (patch)
tree6c0b07effec5eb3ceab76607ecc1bfdffe2051b2 /src/document_tree
parent088c7fc7d38989dd9e523d073e0a717ea57affd6 (diff)
downloadrust-rst-bc5af7498160a9072af5a731f5116ef2db1e30b9.tar.bz2
More into
Diffstat (limited to 'src/document_tree')
-rw-r--r--src/document_tree/element_categories.rs80
1 files changed, 59 insertions, 21 deletions
diff --git a/src/document_tree/element_categories.rs b/src/document_tree/element_categories.rs
index 29da801..16a1e3d 100644
--- a/src/document_tree/element_categories.rs
+++ b/src/document_tree/element_categories.rs
@@ -20,32 +20,49 @@ pub trait HasChildren<C> {
}
}
-macro_rules! synonymous_enum {( $name:ident { $( $entry:ident ),* } ) => (
- #[derive(Serialize)]
- pub enum $name {
- $( $entry($entry), )*
- }
-
- impl Debug for $name {
- fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
- match *self {
- $( $name::$entry(ref inner) => inner.fmt(fmt), )*
+macro_rules! synonymous_enum {
+ ( $name:ident : $super1:ident + $super2:ident { $( $entry:ident ),* $(,)* } ) => {
+ synonymous_enum!($name: $super1 { $( $entry, )* });
+ $( impl Into<$super2> for $entry {
+ fn into(self) -> $super2 {
+ $super2::$super1($super1::$name($name::$entry(self)))
+ }
+ } )*
+ };
+ ( $name:ident : $super:ident { $( $entry:ident ),* $(,)* } ) => {
+ synonymous_enum!($name { $( $entry, )* });
+ $( impl Into<$super> for $entry {
+ fn into(self) -> $super {
+ $super::$name($name::$entry(self))
}
+ } )*
+ };
+ ( $name:ident { $( $entry:ident ),* $(,)* } ) => {
+ #[derive(Serialize)]
+ pub enum $name {
+ $( $entry($entry), )*
}
- }
-
- $(
- impl Into<$name> for $entry {
+
+ impl Debug for $name {
+ fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
+ match *self {
+ $( $name::$entry(ref inner) => inner.fmt(fmt), )*
+ }
+ }
+ }
+
+ $( impl Into<$name> for $entry {
fn into(self) -> $name {
$name::$entry(self)
}
- }
- )*
-)}
+ } )*
+ };
+}
-synonymous_enum!(SubStructure { Topic, Sidebar, Transition, Section, BodyElement });
-synonymous_enum!(StructuralSubElement { Title, Subtitle, Decoration, Docinfo, Transition, SubStructure });
-synonymous_enum!(BodyElement {
+synonymous_enum!(StructuralSubElement { Title, Subtitle, Decoration, Docinfo, SubStructure });
+synonymous_enum!(SubStructure: StructuralSubElement { Topic, Sidebar, Transition, Section, BodyElement });
+//TODO: also implement into: SubTopic, SubSidebar, SubBlockQuote, SubFootnote, SubFigure
+synonymous_enum!(BodyElement: SubStructure + StructuralSubElement {
//Simple
Paragraph, LiteralBlock, DoctestBlock, MathBlock, Rubric, SubstitutionDefinition, Comment, Pending, Target, Raw, Image,
//Compound
@@ -66,7 +83,7 @@ synonymous_enum!(TextOrInlineElement {
//Content Models\\
//--------------\\
-synonymous_enum!(SubSection { Title, Subtitle, Docinfo, Decoration, SubStructure, BodyElement });
+synonymous_enum!(SubSection { Title, Subtitle, Docinfo, Decoration, SubStructure });
synonymous_enum!(AuthorInfo { Author, Organization, Address, Contact });
synonymous_enum!(DecorationElement { Header, Footer });
synonymous_enum!(SubTopic { Title, BodyElement });
@@ -79,3 +96,24 @@ synonymous_enum!(SubLineBlock { LineBlock, Line });
synonymous_enum!(SubBlockQuote { Attribution, BodyElement });
synonymous_enum!(SubFootnote { Label, BodyElement });
synonymous_enum!(SubFigure { Image, Caption, Legend, BodyElement });
+
+#[cfg(test)]
+mod test {
+ use std::default::Default;
+ use super::*;
+
+ #[test]
+ fn test_convert_basic() {
+ let _: BodyElement = Paragraph::default().into();
+ }
+
+ #[test]
+ fn test_convert_more() {
+ let _: SubStructure = Paragraph::default().into();
+ }
+
+ #[test]
+ fn test_convert_super() {
+ let _: StructuralSubElement = BodyElement::Paragraph(Paragraph::default()).into();
+ }
+}