From 1f95ebcc0e4e1393531e3d20e02d750ba0b476d6 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sun, 8 Dec 2019 20:24:47 +0100 Subject: Convenience with_extra_and_children --- src/document_tree/elements.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/document_tree/elements.rs') diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs index f717f6a..7406cd7 100644 --- a/src/document_tree/elements.rs +++ b/src/document_tree/elements.rs @@ -74,6 +74,19 @@ macro_rules! impl_extra { ($name:ident $($more:tt)*) => ( } )} +trait HasExtraAndChildren { + fn with_extra_and_children(extra: A, children: Vec) -> Self; +} + +impl HasExtraAndChildren for T where T: HasChildren + ExtraAttributes { + #[allow(clippy::needless_update)] + fn with_extra_and_children(extra: A, mut children: Vec) -> Self { + let mut r = Self::with_extra(extra); + r.children_mut().extend(children.drain(..)); + r + } +} + macro_rules! impl_new {( $(#[$attr:meta])* pub struct $name:ident { $( -- cgit v1.2.3