From 0ead24a04189754f08b64a261cb5d7fed9126654 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 23 Nov 2017 16:32:18 +0000 Subject: [PATCH] helpers, disco: Parse children based on their name and namespace. --- src/disco.rs | 2 +- src/macros.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/disco.rs b/src/disco.rs index 72dc934a..c48c863c 100644 --- a/src/disco.rs +++ b/src/disco.rs @@ -214,7 +214,7 @@ generate_element_with_children!( ], children: [ /// List of items pointed by this entity. - items: Vec = "item" => Item + items: Vec = ("item", ns::DISCO_ITEMS) => Item ] ); diff --git a/src/macros.rs b/src/macros.rs index 9177009d..b1d9374c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -295,7 +295,7 @@ macro_rules! generate_element_with_text { } macro_rules! generate_element_with_children { - ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+], children: [$($(#[$child_meta:meta])* $child_ident:ident: Vec<$child_type:ty> = $child_name:tt => $child_constructor:ident),+]) => ( + ($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+], children: [$($(#[$child_meta:meta])* $child_ident:ident: Vec<$child_type:ty> = ($child_name:tt, $child_ns:expr) => $child_constructor:ident),+]) => ( $(#[$meta])* #[derive(Debug, Clone)] pub struct $elem { @@ -318,9 +318,13 @@ macro_rules! generate_element_with_children { let mut parsed_children = vec!(); for child in elem.children() { $( - let parsed_child = $child_constructor::try_from(child.clone())?; - parsed_children.push(parsed_child); + if child.is($child_name, $child_ns) { + let parsed_child = $child_constructor::try_from(child.clone())?; + parsed_children.push(parsed_child); + continue; + } )* + return Err(Error::ParseError(concat!("Unknown child in ", $name, " element."))); } Ok($elem { $(