From 323d30b7d6224f098cabe8b274ebf93c7d329bbe Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Sun, 12 Sep 2021 21:45:13 +0100 Subject: [PATCH] Elide __construct_component function --- src/message_ast/convert_matrix.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/message_ast/convert_matrix.rs b/src/message_ast/convert_matrix.rs index a8701a7..d899c25 100644 --- a/src/message_ast/convert_matrix.rs +++ b/src/message_ast/convert_matrix.rs @@ -39,23 +39,14 @@ pub fn convert_matrix(message: &str) -> MessageContent { components.push(MessageComponent::Plain(text.borrow().clone())); } NodeData::Element(element) => { - fn __construct_component( - component_type: fn(MessageContent) -> MessageComponent, - components: MessageContent, - parents: &mut Vec, - ) -> MessageContent { - if let Some(mut parent_components) = parents.pop() { - parent_components.push((component_type)(components)); - parent_components - } else { - vec![] - } - } - macro_rules! construct_component { - ($f:expr) => { - components = __construct_component($f, components, &mut parents); - }; + ($f:expr) => {{ + let component_type = $f; + if let Some(mut parent_components) = parents.pop() { + parent_components.push((component_type)(components)); + components = parent_components; + } + }}; } if element.name.ns == ns!(html) {