aboutsummaryrefslogtreecommitdiffstats
path: root/src/document_tree
diff options
context:
space:
mode:
authorPhilipp A2018-11-19 21:26:38 +0100
committerPhilipp A2018-11-19 21:26:38 +0100
commitde6c16c95806a5d26779c3bc96241dfcab1f18ec (patch)
tree8283ca8371e547a6770180e918d910e2cc3cfc30 /src/document_tree
parent4272b19a79f786c6121e6c18c5aa4da4a4b2e02a (diff)
downloadrust-rst-de6c16c95806a5d26779c3bc96241dfcab1f18ec.tar.bz2
Make it compile again
Diffstat (limited to 'src/document_tree')
-rw-r--r--src/document_tree/element_categories.rs10
-rw-r--r--src/document_tree/elements.rs30
2 files changed, 21 insertions, 19 deletions
diff --git a/src/document_tree/element_categories.rs b/src/document_tree/element_categories.rs
index bc2e347..3a14b16 100644
--- a/src/document_tree/element_categories.rs
+++ b/src/document_tree/element_categories.rs
@@ -1,5 +1,7 @@
use std::fmt::{self,Debug,Formatter};
+use serde::{Serialize,Serializer};
+
use super::elements::*;
pub trait HasChildren<C> {
@@ -31,6 +33,14 @@ macro_rules! synonymous_enum {( $name:ident { $( $entry:ident ),* } ) => (
}
}
+ impl Serialize for $name {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
+ match self {
+ $( $name::$entry(ref inner) => inner.serialize(serializer), )*
+ }
+ }
+ }
+
$(
impl Into<$name> for $entry {
fn into(self) -> $name {
diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs
index 77efa34..681c52e 100644
--- a/src/document_tree/elements.rs
+++ b/src/document_tree/elements.rs
@@ -2,10 +2,7 @@ use url::Url;
use serde::{
Serialize,
Serializer,
- ser::{
- SerializeSeq,
- SerializeStruct,
- },
+ ser::{SerializeStruct},
};
use super::extra_attributes::{self,ExtraAttributes};
@@ -84,29 +81,24 @@ macro_rules! impl_serialize {
($name: ident, $extra: ident, $childtype: ident) => {
impl Serialize for $name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
+ #[allow(unused_mut)]
let mut state = serializer.serialize_struct(stringify!($name), 3)?;
// TODO: common attrs
- impl_serialize_extra!($extra);
- impl_serialize_children!($childtype, self, serializer);
+ impl_cond__! { $extra =>
+
+ }
+ impl_cond__! { $childtype =>
+ state.serialize_field("children", self.children())?;
+ }
state.end()
}
}
};
}
-macro_rules! impl_serialize_extra {
- (__) => {};
- ($name: ident) => {
- // TODO extra_attributes::$name
- };
-}
-
-macro_rules! impl_serialize_children {
- (__, $_: ident, $__: ident) => {};
- ($childtype: ident, $self: ident, $serializer: ident) => {
- use serde::ser::SerializeStruct;
- $serializer.serialize_field("children", $self.children());
- };
+macro_rules! impl_cond__ {
+ (__ => $($b:tt)*) => {};
+ ($thing: ident => $($b:tt)*) => { $($b)* };
}
macro_rules! impl_elem {