From 2db4c81ad664d10ffd656f78481930b9395ce776 Mon Sep 17 00:00:00 2001 From: Lucille Blumire Date: Sat, 23 Apr 2022 13:06:41 +0100 Subject: [PATCH] Add `VTag::into_children` (#2638) * Add `VTag::into_children` Currently, VTag supports `children` and `children_mut`, but not `into_children` to complete the pattern. This is useful if someone wishes to destructively acquire the children of a VTag to reparent them to a different VTag. * Repair broken doc comment on `VTag::children_mut` * Remove spaces between functions --- packages/yew/src/virtual_dom/vtag.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/yew/src/virtual_dom/vtag.rs b/packages/yew/src/virtual_dom/vtag.rs index 03c4d7d6dcd..9afdfb384fa 100644 --- a/packages/yew/src/virtual_dom/vtag.rs +++ b/packages/yew/src/virtual_dom/vtag.rs @@ -297,7 +297,7 @@ impl VTag { } /// Returns a mutable reference to the children of this [VTag], if the node can have - // children + /// children pub fn children_mut(&mut self) -> Option<&mut VList> { match &mut self.inner { VTagInner::Other { children, .. } => Some(children), @@ -305,6 +305,14 @@ impl VTag { } } + /// Returns the children of this [VTag] + pub fn into_children(self) -> VList { + match self.inner { + VTagInner::Other { children, .. } => children, + _ => VList::new(), + } + } + /// Returns the `value` of an /// [InputElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) or /// [TextArea](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea)