Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions packages/yew-macro/tests/html_macro/component-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,14 @@ error[E0277]: the trait bound `{integer}: IntoPropValue<String>` is not satisfie
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoPropValue<T>`:
f32
f64
i128
i16
i32
i64
i8
isize
&f32
&f64
&i128
&i16
&i32
&i64
&i8
&isize
and $N others
note: required by a bound in `ChildPropertiesBuilder::string`
--> tests/html_macro/component-fail.rs:4:17
Expand All @@ -516,14 +516,14 @@ error[E0277]: the trait bound `{integer}: IntoPropValue<String>` is not satisfie
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoPropValue<T>`:
f32
f64
i128
i16
i32
i64
i8
isize
&f32
&f64
&i128
&i16
&i32
&i64
&i8
&isize
and $N others
note: required by a bound in `ChildPropertiesBuilder::string`
--> tests/html_macro/component-fail.rs:4:17
Expand Down Expand Up @@ -560,9 +560,9 @@ error[E0277]: the trait bound `u32: IntoPropValue<i32>` is not satisfied
| |
| required by a bound introduced by this call
|
= help: the trait `IntoPropValue<i32>` is not implemented for `u32`
but trait `IntoPropValue<VNode>` is implemented for it
= help: for that trait implementation, expected `VNode`, found `i32`
= help: the following other types implement trait `IntoPropValue<T>`:
&u32
u32
note: required by a bound in `ChildPropertiesBuilder::int`
--> tests/html_macro/component-fail.rs:4:17
|
Expand Down
14 changes: 7 additions & 7 deletions packages/yew-macro/tests/html_macro/element-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,14 @@ error[E0277]: the trait bound `NotToString: IntoPropValue<Option<implicit_clone:
| ^^^^^^^^^^^ the trait `IntoPropValue<Option<implicit_clone::unsync::string::IString>>` is not implemented for `NotToString`
|
= help: the following other types implement trait `IntoPropValue<T>`:
`&&String` implements `IntoPropValue<VNode>`
`&&str` implements `IntoPropValue<VNode>`
`&'static [(K, V)]` implements `IntoPropValue<implicit_clone::unsync::map::IMap<K, V>>`
`&'static [T]` implements `IntoPropValue<implicit_clone::unsync::array::IArray<T>>`
`&'static str` implements `IntoPropValue<Classes>`
`&'static str` implements `IntoPropValue<Option<String>>`
`&'static str` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`&'static str` implements `IntoPropValue<String>`
`&'static str` implements `IntoPropValue<implicit_clone::unsync::string::IString>`
`&ChildrenRenderer<VNode>` implements `IntoPropValue<VNode>`
and $N others

error[E0277]: the trait bound `Option<NotToString>: IntoPropValue<Option<implicit_clone::unsync::string::IString>>` is not satisfied
Expand All @@ -491,8 +491,8 @@ error[E0277]: the trait bound `Option<NotToString>: IntoPropValue<Option<implici
`Option<F>` implements `IntoPropValue<Option<yew::Callback<I, O>>>`
`Option<Rc<str>>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`Option<String>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`Option<T>` implements `IntoPropValue<VNode>`
`Option<VChild<T>>` implements `IntoPropValue<Option<ChildrenRenderer<C>>>`
`Option<VNode>` implements `IntoPropValue<VNode>`

error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<implicit_clone::unsync::string::IString>>` is not satisfied
--> tests/html_macro/element-fail.rs:48:22
Expand All @@ -510,8 +510,8 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<implicit_
`Option<F>` implements `IntoPropValue<Option<yew::Callback<I, O>>>`
`Option<Rc<str>>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`Option<String>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`Option<T>` implements `IntoPropValue<VNode>`
`Option<VChild<T>>` implements `IntoPropValue<Option<ChildrenRenderer<C>>>`
`Option<VNode>` implements `IntoPropValue<VNode>`

error[E0277]: the trait bound `{integer}: IntoEventCallback<MouseEvent>` is not satisfied
--> tests/html_macro/element-fail.rs:51:28
Expand Down Expand Up @@ -627,8 +627,8 @@ error[E0277]: the trait bound `Option<yew::NodeRef>: IntoPropValue<yew::NodeRef>
`Option<F>` implements `IntoPropValue<Option<yew::Callback<I, O>>>`
`Option<Rc<str>>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`Option<String>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`Option<T>` implements `IntoPropValue<VNode>`
`Option<VChild<T>>` implements `IntoPropValue<Option<ChildrenRenderer<C>>>`
`Option<VNode>` implements `IntoPropValue<VNode>`

error[E0277]: the trait bound `yew::Callback<String>: IntoEventCallback<MouseEvent>` is not satisfied
--> tests/html_macro/element-fail.rs:58:29
Expand Down Expand Up @@ -665,14 +665,14 @@ error[E0277]: the trait bound `NotToString: IntoPropValue<Option<implicit_clone:
| ^^^^^^^^^^^ the trait `IntoPropValue<Option<implicit_clone::unsync::string::IString>>` is not implemented for `NotToString`
|
= help: the following other types implement trait `IntoPropValue<T>`:
`&&String` implements `IntoPropValue<VNode>`
`&&str` implements `IntoPropValue<VNode>`
`&'static [(K, V)]` implements `IntoPropValue<implicit_clone::unsync::map::IMap<K, V>>`
`&'static [T]` implements `IntoPropValue<implicit_clone::unsync::array::IArray<T>>`
`&'static str` implements `IntoPropValue<Classes>`
`&'static str` implements `IntoPropValue<Option<String>>`
`&'static str` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`&'static str` implements `IntoPropValue<String>`
`&'static str` implements `IntoPropValue<implicit_clone::unsync::string::IString>`
`&ChildrenRenderer<VNode>` implements `IntoPropValue<VNode>`
and $N others

error[E0277]: the trait bound `(): IntoPropValue<yew::NodeRef>` is not satisfied
Expand Down
20 changes: 20 additions & 0 deletions packages/yew-macro/tests/html_macro/html-element-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ fn compile_pass() {

let option_vnode = ::std::option::Option::Some(::yew::html! {});
_ = ::yew::html! { <div>{option_vnode}</div> };

let opt_string: ::std::option::Option<::std::string::String> =
::std::option::Option::Some(::std::convert::From::from("hello"));
_ = ::yew::html! { <div>{opt_string}</div> };

let opt_attr: ::std::option::Option<::yew::AttrValue> =
::std::option::Option::Some(::yew::AttrValue::Static("hello"));
_ = ::yew::html! { <div>{opt_attr}</div> };

let opt_none: ::std::option::Option<::std::string::String> = ::std::option::Option::None;
_ = ::yew::html! { <div>{opt_none}</div> };

let num = 42i32;
_ = ::yew::html! { <div>{&num}</div> };

let text = ::std::string::String::new();
_ = ::yew::html! { <div>{&text}</div> };

let sr: &::core::primitive::str = "hello";
_ = ::yew::html! { <div>{&sr}</div> };
}

fn main() {}
35 changes: 33 additions & 2 deletions packages/yew/src/html/conversion/into_prop_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ impl IntoPropValue<VNode> for Vec<VNode> {
}
}

impl IntoPropValue<VNode> for Option<VNode> {
impl<T: IntoPropValue<VNode>> IntoPropValue<VNode> for Option<T> {
#[inline]
fn into_prop_value(self) -> VNode {
self.unwrap_or_default()
self.map(IntoPropValue::into_prop_value).unwrap_or_default()
}
}

Expand Down Expand Up @@ -292,6 +292,12 @@ macro_rules! impl_into_prop_value_via_display {
VText::from(self).into()
}
}
impl IntoPropValue<VNode> for &$from_ty {
#[inline(always)]
fn into_prop_value(self) -> VNode {
self.clone().into_prop_value()
}
}
};
}

Expand Down Expand Up @@ -350,6 +356,31 @@ mod test {
let _: Option<AttrValue> = Cow::Borrowed("foo").into_prop_value();
}

#[test]
fn test_option_to_vnode() {
let _: VNode = Some(String::from("hello")).into_prop_value();
let _: VNode = Some(AttrValue::Static("hello")).into_prop_value();
let _: VNode = Option::<String>::None.into_prop_value();
let _: VNode = Option::<AttrValue>::None.into_prop_value();
let _: VNode = Some(VNode::default()).into_prop_value();
let _: VNode = Option::<VNode>::None.into_prop_value();
let _: VNode = Some(42u32).into_prop_value();
let _: VNode = Some(true).into_prop_value();
}

#[test]
fn test_ref_to_vnode() {
let _: VNode = (&42i32).into_prop_value();
let _: VNode = (&true).into_prop_value();
let _: VNode = (&1.5f64).into_prop_value();
let s = String::from("hello");
let _: VNode = (&s).into_prop_value();
let a = AttrValue::Static("hello");
let _: VNode = (&a).into_prop_value();
let sr: &str = "hello";
let _: VNode = (&sr).into_prop_value();
}

#[test]
fn test_callback() {
let _: Callback<String> = (|_: String| ()).into_prop_value();
Expand Down
2 changes: 1 addition & 1 deletion website/docs/advanced-topics/children.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Component for Page {
fn view(&self, ctx: &Context<Self>) -> Html {
html! {
<div class="page">
{ ctx.props().sidebar.clone().map(Html::from).unwrap_or_default() }
{ ctx.props().sidebar.clone() }
// ... page content
</div>
}
Expand Down
Loading