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
38 changes: 20 additions & 18 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` implements `IntoPropValue<Option<VNode>>`
`&f32` implements `IntoPropValue<VNode>`
`&f64` implements `IntoPropValue<Option<VNode>>`
`&f64` implements `IntoPropValue<VNode>`
`&i128` implements `IntoPropValue<Option<VNode>>`
`&i128` implements `IntoPropValue<VNode>`
`&i16` implements `IntoPropValue<Option<VNode>>`
`&i16` implements `IntoPropValue<VNode>`
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` implements `IntoPropValue<Option<VNode>>`
`&f32` implements `IntoPropValue<VNode>`
`&f64` implements `IntoPropValue<Option<VNode>>`
`&f64` implements `IntoPropValue<VNode>`
`&i128` implements `IntoPropValue<Option<VNode>>`
`&i128` implements `IntoPropValue<VNode>`
`&i16` implements `IntoPropValue<Option<VNode>>`
`&i16` implements `IntoPropValue<VNode>`
and $N others
note: required by a bound in `ChildPropertiesBuilder::string`
--> tests/html_macro/component-fail.rs:4:17
Expand Down Expand Up @@ -561,8 +561,10 @@ error[E0277]: the trait bound `u32: IntoPropValue<i32>` is not satisfied
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoPropValue<T>`:
&u32
u32
`&u32` implements `IntoPropValue<Option<VNode>>`
`&u32` implements `IntoPropValue<VNode>`
`u32` implements `IntoPropValue<Option<VNode>>`
`u32` implements `IntoPropValue<VNode>`
note: required by a bound in `ChildPropertiesBuilder::int`
--> tests/html_macro/component-fail.rs:4:17
|
Expand Down
47 changes: 25 additions & 22 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<Option<VNode>>`
`&&String` implements `IntoPropValue<VNode>`
`&&str` implements `IntoPropValue<Option<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>`
and $N others

error[E0277]: the trait bound `Option<NotToString>: IntoPropValue<Option<implicit_clone::unsync::string::IString>>` is not satisfied
Expand All @@ -485,14 +485,15 @@ error[E0277]: the trait bound `Option<NotToString>: IntoPropValue<Option<implici
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoPropValue<T>`:
`Option<&String>` implements `IntoPropValue<Option<VNode>>`
`Option<&implicit_clone::unsync::string::IString>` implements `IntoPropValue<Option<VNode>>`
`Option<&str>` implements `IntoPropValue<Option<String>>`
`Option<&str>` implements `IntoPropValue<Option<VNode>>`
`Option<&str>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`Option<Cow<'_, str>>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`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<Arc<String>>` implements `IntoPropValue<Option<VNode>>`
`Option<Arc<str>>` implements `IntoPropValue<Option<VNode>>`
`Option<Cow<'_, str>>` implements `IntoPropValue<Option<VNode>>`
and $N others

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 @@ -504,14 +505,15 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<implicit_
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoPropValue<T>`:
`Option<&String>` implements `IntoPropValue<Option<VNode>>`
`Option<&implicit_clone::unsync::string::IString>` implements `IntoPropValue<Option<VNode>>`
`Option<&str>` implements `IntoPropValue<Option<String>>`
`Option<&str>` implements `IntoPropValue<Option<VNode>>`
`Option<&str>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`Option<Cow<'_, str>>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`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<Arc<String>>` implements `IntoPropValue<Option<VNode>>`
`Option<Arc<str>>` implements `IntoPropValue<Option<VNode>>`
`Option<Cow<'_, str>>` implements `IntoPropValue<Option<VNode>>`
and $N others

error[E0277]: the trait bound `{integer}: IntoEventCallback<MouseEvent>` is not satisfied
--> tests/html_macro/element-fail.rs:51:28
Expand Down Expand Up @@ -621,14 +623,15 @@ error[E0277]: the trait bound `Option<yew::NodeRef>: IntoPropValue<yew::NodeRef>
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoPropValue<T>`:
`Option<&String>` implements `IntoPropValue<Option<VNode>>`
`Option<&implicit_clone::unsync::string::IString>` implements `IntoPropValue<Option<VNode>>`
`Option<&str>` implements `IntoPropValue<Option<String>>`
`Option<&str>` implements `IntoPropValue<Option<VNode>>`
`Option<&str>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`Option<Cow<'_, str>>` implements `IntoPropValue<Option<implicit_clone::unsync::string::IString>>`
`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<Arc<String>>` implements `IntoPropValue<Option<VNode>>`
`Option<Arc<str>>` implements `IntoPropValue<Option<VNode>>`
`Option<Cow<'_, str>>` implements `IntoPropValue<Option<VNode>>`
and $N others

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 +668,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<Option<VNode>>`
`&&String` implements `IntoPropValue<VNode>`
`&&str` implements `IntoPropValue<Option<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>`
and $N others

error[E0277]: the trait bound `(): IntoPropValue<yew::NodeRef>` is not satisfied
Expand Down
78 changes: 78 additions & 0 deletions packages/yew/src/html/conversion/into_prop_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,24 @@ macro_rules! impl_into_prop_value_via_display {
self.clone().into_prop_value()
}
}
impl IntoPropValue<Option<VNode>> for $from_ty {
#[inline(always)]
fn into_prop_value(self) -> Option<VNode> {
Some(IntoPropValue::<VNode>::into_prop_value(self))
}
}
impl IntoPropValue<Option<VNode>> for &$from_ty {
#[inline(always)]
fn into_prop_value(self) -> Option<VNode> {
Some(IntoPropValue::<VNode>::into_prop_value(self))
}
}
impl IntoPropValue<Option<VNode>> for Option<$from_ty> {
#[inline(always)]
fn into_prop_value(self) -> Option<VNode> {
self.map(IntoPropValue::<VNode>::into_prop_value)
}
}
};
}

Expand All @@ -310,6 +328,18 @@ macro_rules! impl_into_prop_value_via_attr_value {
VText::new(self).into()
}
}
impl IntoPropValue<Option<VNode>> for $from_ty {
#[inline(always)]
fn into_prop_value(self) -> Option<VNode> {
Some(VText::new(self).into())
}
}
impl IntoPropValue<Option<VNode>> for Option<$from_ty> {
#[inline(always)]
fn into_prop_value(self) -> Option<VNode> {
self.map(|v| VText::new(v).into())
}
}
};
}

Expand Down Expand Up @@ -368,6 +398,28 @@ mod test {
let _: VNode = Some(true).into_prop_value();
}

#[test]
fn test_into_option_vnode() {
// T -> Option<VNode>
let _: Option<VNode> = "hello".into_prop_value();
let _: Option<VNode> = String::from("hello").into_prop_value();
let _: Option<VNode> = AttrValue::Static("hello").into_prop_value();
let _: Option<VNode> = 42u32.into_prop_value();
let _: Option<VNode> = true.into_prop_value();
// &T -> Option<VNode>
let _: Option<VNode> = (&42u32).into_prop_value();
let _: Option<VNode> = (&true).into_prop_value();
let s = String::from("hello");
let _: Option<VNode> = (&s).into_prop_value();
// Option<T> -> Option<VNode>
let _: Option<VNode> = Some("hello").into_prop_value();
let _: Option<VNode> = Option::<&str>::None.into_prop_value();
let _: Option<VNode> = Some(String::from("hello")).into_prop_value();
let _: Option<VNode> = Option::<String>::None.into_prop_value();
let _: Option<VNode> = Some(42u32).into_prop_value();
let _: Option<VNode> = Some(true).into_prop_value();
}

#[test]
fn test_ref_to_vnode() {
let _: VNode = (&42i32).into_prop_value();
Expand Down Expand Up @@ -646,4 +698,30 @@ mod test {
let _ = html! { <Comp foo="hello" /> };
let _ = html! { <Comp /> };
}

#[test]
fn test_option_html_prop_compiles() {
use crate::prelude::*;

#[derive(PartialEq, Properties)]
pub struct Props {
pub title: Option<Html>,
}

#[component]
fn Foo(props: &Props) -> Html {
match &props.title {
Some(title) => html! { <h1>{ title.clone() }</h1> },
None => html! {},
}
}

let _ = html! { <Foo title="Title" /> };

let _ = html! { <Foo title={String::from("Title")} /> };

let _ = html! { <Foo title={Some("Title")} /> };

let _ = html! { <Foo title={Option::<Html>::None} /> };
}
}
Loading