From 81f7ea482bf9b75e2294258816a77b12791f39ea Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 14 Sep 2022 15:04:12 +0200 Subject: [PATCH] implement html from Option (#2792) Co-authored-by: Martin Molzer --- packages/yew-macro/tests/html_macro/html-element-pass.rs | 3 +++ packages/yew/src/utils/mod.rs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/yew-macro/tests/html_macro/html-element-pass.rs b/packages/yew-macro/tests/html_macro/html-element-pass.rs index dfd323f9f91..dc81c66db22 100644 --- a/packages/yew-macro/tests/html_macro/html-element-pass.rs +++ b/packages/yew-macro/tests/html_macro/html-element-pass.rs @@ -121,6 +121,9 @@ fn compile_pass() { // test for https://github.com/yewstack/yew/issues/2810 ::yew::html! {
}; + + let option_vnode = ::std::option::Option::Some(::yew::html! {}); + ::yew::html! {
{option_vnode}
}; } fn main() {} diff --git a/packages/yew/src/utils/mod.rs b/packages/yew/src/utils/mod.rs index e5b999e72c5..29d537af5b9 100644 --- a/packages/yew/src/utils/mod.rs +++ b/packages/yew/src/utils/mod.rs @@ -23,6 +23,15 @@ impl, OUT> From for NodeSeq { } } +impl, OUT> From> for NodeSeq { + fn from(val: Option) -> Self { + Self( + val.map(|s| vec![s.into()]).unwrap_or_default(), + PhantomData::default(), + ) + } +} + impl, OUT> From> for NodeSeq { fn from(val: Vec) -> Self { Self(