mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Bring back &str assignment to optional properties (#1895)
This drops the "optional" conversion concept in favor of directly converting to `Option<T>`. fixes #1888
This commit is contained in:
parent
9aaeef217d
commit
b03f02f624
@ -22,9 +22,9 @@ error[E0599]: the function or associated item `new` exists for struct `VChild<Fu
|
|||||||
28 | html! { <Comp<MissingTypeBounds> /> };
|
28 | html! { <Comp<MissingTypeBounds> /> };
|
||||||
| ^^^^ function or associated item cannot be called on `VChild<FunctionComponent<comp<MissingTypeBounds>>>` due to unsatisfied trait bounds
|
| ^^^^ function or associated item cannot be called on `VChild<FunctionComponent<comp<MissingTypeBounds>>>` due to unsatisfied trait bounds
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew-functional/src/lib.rs
|
::: $WORKSPACE/packages/yew-functional/src/lib.rs:73:1
|
||||||
|
|
|
|
||||||
| pub struct FunctionComponent<T: FunctionProvider + 'static> {
|
73 | pub struct FunctionComponent<T: FunctionProvider + 'static> {
|
||||||
| ----------------------------------------------------------- doesn't satisfy `_: yew::Component`
|
| ----------------------------------------------------------- doesn't satisfy `_: yew::Component`
|
||||||
|
|
|
|
||||||
= note: the following trait bounds were not satisfied:
|
= note: the following trait bounds were not satisfied:
|
||||||
|
|||||||
@ -34,9 +34,9 @@ error[E0277]: `()` doesn't implement `std::fmt::Display`
|
|||||||
15 | <>{ for (0..3).map(|_| not_tree()) }</>
|
15 | <>{ for (0..3).map(|_| not_tree()) }</>
|
||||||
| ^^^^^^ `()` cannot be formatted with the default formatter
|
| ^^^^^^ `()` cannot be formatted with the default formatter
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew/src/utils.rs
|
::: $WORKSPACE/packages/yew/src/utils.rs:51:8
|
||||||
|
|
|
|
||||||
| T: Into<R>,
|
51 | T: Into<R>,
|
||||||
| ------- required by this bound in `into_node_iter`
|
| ------- required by this bound in `into_node_iter`
|
||||||
|
|
|
|
||||||
= help: the trait `std::fmt::Display` is not implemented for `()`
|
= help: the trait `std::fmt::Display` is not implemented for `()`
|
||||||
|
|||||||
@ -213,10 +213,10 @@ error[E0277]: the trait bound `{integer}: IntoPropValue<String>` is not satisfie
|
|||||||
|
|
|
|
||||||
= help: the following implementations were found:
|
= help: the following implementations were found:
|
||||||
<&'static str as IntoPropValue<Cow<'static, str>>>
|
<&'static str as IntoPropValue<Cow<'static, str>>>
|
||||||
|
<&'static str as IntoPropValue<Option<Cow<'static, str>>>>
|
||||||
|
<&'static str as IntoPropValue<Option<String>>>
|
||||||
<&'static str as IntoPropValue<String>>
|
<&'static str as IntoPropValue<String>>
|
||||||
<&T as IntoPropValue<Option<T>>>
|
and 11 others
|
||||||
<&T as IntoPropValue<T>>
|
|
||||||
and 4 others
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `{integer}: IntoPropValue<String>` is not satisfied
|
error[E0277]: the trait bound `{integer}: IntoPropValue<String>` is not satisfied
|
||||||
--> $DIR/component-fail.rs:79:26
|
--> $DIR/component-fail.rs:79:26
|
||||||
@ -226,10 +226,10 @@ error[E0277]: the trait bound `{integer}: IntoPropValue<String>` is not satisfie
|
|||||||
|
|
|
|
||||||
= help: the following implementations were found:
|
= help: the following implementations were found:
|
||||||
<&'static str as IntoPropValue<Cow<'static, str>>>
|
<&'static str as IntoPropValue<Cow<'static, str>>>
|
||||||
|
<&'static str as IntoPropValue<Option<Cow<'static, str>>>>
|
||||||
|
<&'static str as IntoPropValue<Option<String>>>
|
||||||
<&'static str as IntoPropValue<String>>
|
<&'static str as IntoPropValue<String>>
|
||||||
<&T as IntoPropValue<Option<T>>>
|
and 11 others
|
||||||
<&T as IntoPropValue<T>>
|
|
||||||
and 4 others
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/component-fail.rs:80:30
|
--> $DIR/component-fail.rs:80:30
|
||||||
|
|||||||
@ -185,16 +185,12 @@ error[E0277]: the trait bound `(): IntoPropValue<Option<Cow<'static, str>>>` is
|
|||||||
|
|
|
|
||||||
43 | html! { <input type=() /> };
|
43 | html! { <input type=() /> };
|
||||||
| ^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `()`
|
| ^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `()`
|
||||||
|
|
|
||||||
= note: required because of the requirements on the impl of `IntoOptPropValue<Cow<'static, str>>` for `()`
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `(): IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
error[E0277]: the trait bound `(): IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
||||||
--> $DIR/element-fail.rs:44:26
|
--> $DIR/element-fail.rs:44:26
|
||||||
|
|
|
|
||||||
44 | html! { <input value=() /> };
|
44 | html! { <input value=() /> };
|
||||||
| ^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `()`
|
| ^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `()`
|
||||||
|
|
|
||||||
= note: required because of the requirements on the impl of `IntoOptPropValue<Cow<'static, str>>` for `()`
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `(): IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
error[E0277]: the trait bound `(): IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
||||||
--> $DIR/element-fail.rs:45:21
|
--> $DIR/element-fail.rs:45:21
|
||||||
@ -202,12 +198,10 @@ error[E0277]: the trait bound `(): IntoPropValue<Option<Cow<'static, str>>>` is
|
|||||||
45 | html! { <a href=() /> };
|
45 | html! { <a href=() /> };
|
||||||
| ^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `()`
|
| ^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `()`
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew/src/virtual_dom/mod.rs
|
::: $WORKSPACE/packages/yew/src/virtual_dom/mod.rs:61:47
|
||||||
|
|
|
|
||||||
| pub fn new(key: &'static str, value: impl IntoOptPropValue<AttrValue>) -> Self {
|
61 | pub fn new(key: &'static str, value: impl IntoPropValue<Option<AttrValue>>) -> Self {
|
||||||
| --------------------------- required by this bound in `PositionalAttr::new`
|
| -------------------------------- required by this bound in `PositionalAttr::new`
|
||||||
|
|
|
||||||
= note: required because of the requirements on the impl of `IntoOptPropValue<Cow<'static, str>>` for `()`
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `NotToString: IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
error[E0277]: the trait bound `NotToString: IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
||||||
--> $DIR/element-fail.rs:46:27
|
--> $DIR/element-fail.rs:46:27
|
||||||
@ -215,12 +209,10 @@ error[E0277]: the trait bound `NotToString: IntoPropValue<Option<Cow<'static, st
|
|||||||
46 | html! { <input string=NotToString /> };
|
46 | html! { <input string=NotToString /> };
|
||||||
| ^^^^^^^^^^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `NotToString`
|
| ^^^^^^^^^^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `NotToString`
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew/src/virtual_dom/mod.rs
|
::: $WORKSPACE/packages/yew/src/virtual_dom/mod.rs:61:47
|
||||||
|
|
|
|
||||||
| pub fn new(key: &'static str, value: impl IntoOptPropValue<AttrValue>) -> Self {
|
61 | pub fn new(key: &'static str, value: impl IntoPropValue<Option<AttrValue>>) -> Self {
|
||||||
| --------------------------- required by this bound in `PositionalAttr::new`
|
| -------------------------------- required by this bound in `PositionalAttr::new`
|
||||||
|
|
|
||||||
= note: required because of the requirements on the impl of `IntoOptPropValue<Cow<'static, str>>` for `NotToString`
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `Option<NotToString>: IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
error[E0277]: the trait bound `Option<NotToString>: IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
||||||
--> $DIR/element-fail.rs:47:22
|
--> $DIR/element-fail.rs:47:22
|
||||||
@ -228,12 +220,15 @@ error[E0277]: the trait bound `Option<NotToString>: IntoPropValue<Option<Cow<'st
|
|||||||
47 | html! { <a media=Some(NotToString) /> };
|
47 | html! { <a media=Some(NotToString) /> };
|
||||||
| ^^^^^^^^^^^^^^^^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `Option<NotToString>`
|
| ^^^^^^^^^^^^^^^^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `Option<NotToString>`
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew/src/virtual_dom/mod.rs
|
::: $WORKSPACE/packages/yew/src/virtual_dom/mod.rs:61:47
|
||||||
|
|
|
|
||||||
| pub fn new(key: &'static str, value: impl IntoOptPropValue<AttrValue>) -> Self {
|
61 | pub fn new(key: &'static str, value: impl IntoPropValue<Option<AttrValue>>) -> Self {
|
||||||
| --------------------------- required by this bound in `PositionalAttr::new`
|
| -------------------------------- required by this bound in `PositionalAttr::new`
|
||||||
|
|
|
|
||||||
= note: required because of the requirements on the impl of `IntoOptPropValue<Cow<'static, str>>` for `Option<NotToString>`
|
= help: the following implementations were found:
|
||||||
|
<Option<&'static str> as IntoPropValue<Option<Cow<'static, str>>>>
|
||||||
|
<Option<&'static str> as IntoPropValue<Option<String>>>
|
||||||
|
<Option<String> as IntoPropValue<Option<Cow<'static, str>>>>
|
||||||
|
|
||||||
error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
|
||||||
--> $DIR/element-fail.rs:48:21
|
--> $DIR/element-fail.rs:48:21
|
||||||
@ -241,12 +236,15 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<Cow<'stat
|
|||||||
48 | html! { <a href=Some(5) /> };
|
48 | html! { <a href=Some(5) /> };
|
||||||
| ^^^^^^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `Option<{integer}>`
|
| ^^^^^^^ the trait `IntoPropValue<Option<Cow<'static, str>>>` is not implemented for `Option<{integer}>`
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew/src/virtual_dom/mod.rs
|
::: $WORKSPACE/packages/yew/src/virtual_dom/mod.rs:61:47
|
||||||
|
|
|
|
||||||
| pub fn new(key: &'static str, value: impl IntoOptPropValue<AttrValue>) -> Self {
|
61 | pub fn new(key: &'static str, value: impl IntoPropValue<Option<AttrValue>>) -> Self {
|
||||||
| --------------------------- required by this bound in `PositionalAttr::new`
|
| -------------------------------- required by this bound in `PositionalAttr::new`
|
||||||
|
|
|
|
||||||
= note: required because of the requirements on the impl of `IntoOptPropValue<Cow<'static, str>>` for `Option<{integer}>`
|
= help: the following implementations were found:
|
||||||
|
<Option<&'static str> as IntoPropValue<Option<Cow<'static, str>>>>
|
||||||
|
<Option<&'static str> as IntoPropValue<Option<String>>>
|
||||||
|
<Option<String> as IntoPropValue<Option<Cow<'static, str>>>>
|
||||||
|
|
||||||
error[E0277]: the trait bound `{integer}: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
|
error[E0277]: the trait bound `{integer}: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
|
||||||
--> $DIR/element-fail.rs:51:28
|
--> $DIR/element-fail.rs:51:28
|
||||||
@ -254,9 +252,9 @@ error[E0277]: the trait bound `{integer}: IntoPropValue<Option<yew::Callback<Mou
|
|||||||
51 | html! { <input onclick=1 /> };
|
51 | html! { <input onclick=1 /> };
|
||||||
| ^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `{integer}`
|
| ^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `{integer}`
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew/src/html/listener/events.rs
|
::: $WORKSPACE/packages/yew/src/html/listener/events.rs:2:1
|
||||||
|
|
|
|
||||||
| / impl_action! {
|
2 | / impl_action! {
|
||||||
3 | | onabort(name: "abort", event: Event) -> web_sys::Event => |_, event| { event }
|
3 | | onabort(name: "abort", event: Event) -> web_sys::Event => |_, event| { event }
|
||||||
4 | | onauxclick(name: "auxclick", event: MouseEvent) -> web_sys::MouseEvent => |_, event| { event }
|
4 | | onauxclick(name: "auxclick", event: MouseEvent) -> web_sys::MouseEvent => |_, event| { event }
|
||||||
5 | | onblur(name: "blur", event: FocusEvent) -> web_sys::FocusEvent => |_, event| { event }
|
5 | | onblur(name: "blur", event: FocusEvent) -> web_sys::FocusEvent => |_, event| { event }
|
||||||
@ -267,11 +265,10 @@ error[E0277]: the trait bound `{integer}: IntoPropValue<Option<yew::Callback<Mou
|
|||||||
|
|
|
|
||||||
= help: the following implementations were found:
|
= help: the following implementations were found:
|
||||||
<&'static str as IntoPropValue<Cow<'static, str>>>
|
<&'static str as IntoPropValue<Cow<'static, str>>>
|
||||||
|
<&'static str as IntoPropValue<Option<Cow<'static, str>>>>
|
||||||
|
<&'static str as IntoPropValue<Option<String>>>
|
||||||
<&'static str as IntoPropValue<String>>
|
<&'static str as IntoPropValue<String>>
|
||||||
<&T as IntoPropValue<Option<T>>>
|
and 11 others
|
||||||
<&T as IntoPropValue<T>>
|
|
||||||
and 4 others
|
|
||||||
= note: required because of the requirements on the impl of `IntoOptPropValue<yew::Callback<MouseEvent>>` for `{integer}`
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
|
error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
|
||||||
--> $DIR/element-fail.rs:52:28
|
--> $DIR/element-fail.rs:52:28
|
||||||
@ -279,9 +276,9 @@ error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::
|
|||||||
52 | html! { <input onclick=Callback::from(|a: String| ()) /> };
|
52 | html! { <input onclick=Callback::from(|a: String| ()) /> };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `yew::Callback<String>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `yew::Callback<String>`
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew/src/html/listener/events.rs
|
::: $WORKSPACE/packages/yew/src/html/listener/events.rs:2:1
|
||||||
|
|
|
|
||||||
| / impl_action! {
|
2 | / impl_action! {
|
||||||
3 | | onabort(name: "abort", event: Event) -> web_sys::Event => |_, event| { event }
|
3 | | onabort(name: "abort", event: Event) -> web_sys::Event => |_, event| { event }
|
||||||
4 | | onauxclick(name: "auxclick", event: MouseEvent) -> web_sys::MouseEvent => |_, event| { event }
|
4 | | onauxclick(name: "auxclick", event: MouseEvent) -> web_sys::MouseEvent => |_, event| { event }
|
||||||
5 | | onblur(name: "blur", event: FocusEvent) -> web_sys::FocusEvent => |_, event| { event }
|
5 | | onblur(name: "blur", event: FocusEvent) -> web_sys::FocusEvent => |_, event| { event }
|
||||||
@ -289,8 +286,6 @@ error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::
|
|||||||
99 | | ontransitionstart(name: "transitionstart", event: TransitionEvent) -> web_sys::TransitionEvent => |_, event| { event }
|
99 | | ontransitionstart(name: "transitionstart", event: TransitionEvent) -> web_sys::TransitionEvent => |_, event| { event }
|
||||||
100 | | }
|
100 | | }
|
||||||
| |_- required by this bound in `yew::html::onclick::Wrapper::__macro_new`
|
| |_- required by this bound in `yew::html::onclick::Wrapper::__macro_new`
|
||||||
|
|
|
||||||
= note: required because of the requirements on the impl of `IntoOptPropValue<yew::Callback<MouseEvent>>` for `yew::Callback<String>`
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<yew::Callback<FocusEvent>>>` is not satisfied
|
error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<yew::Callback<FocusEvent>>>` is not satisfied
|
||||||
--> $DIR/element-fail.rs:53:28
|
--> $DIR/element-fail.rs:53:28
|
||||||
@ -298,9 +293,9 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<yew::Call
|
|||||||
53 | html! { <input onfocus=Some(5) /> };
|
53 | html! { <input onfocus=Some(5) /> };
|
||||||
| ^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<FocusEvent>>>` is not implemented for `Option<{integer}>`
|
| ^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<FocusEvent>>>` is not implemented for `Option<{integer}>`
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew/src/html/listener/events.rs
|
::: $WORKSPACE/packages/yew/src/html/listener/events.rs:2:1
|
||||||
|
|
|
|
||||||
| / impl_action! {
|
2 | / impl_action! {
|
||||||
3 | | onabort(name: "abort", event: Event) -> web_sys::Event => |_, event| { event }
|
3 | | onabort(name: "abort", event: Event) -> web_sys::Event => |_, event| { event }
|
||||||
4 | | onauxclick(name: "auxclick", event: MouseEvent) -> web_sys::MouseEvent => |_, event| { event }
|
4 | | onauxclick(name: "auxclick", event: MouseEvent) -> web_sys::MouseEvent => |_, event| { event }
|
||||||
5 | | onblur(name: "blur", event: FocusEvent) -> web_sys::FocusEvent => |_, event| { event }
|
5 | | onblur(name: "blur", event: FocusEvent) -> web_sys::FocusEvent => |_, event| { event }
|
||||||
@ -309,7 +304,10 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<yew::Call
|
|||||||
100 | | }
|
100 | | }
|
||||||
| |_- required by this bound in `yew::html::onfocus::Wrapper::__macro_new`
|
| |_- required by this bound in `yew::html::onfocus::Wrapper::__macro_new`
|
||||||
|
|
|
|
||||||
= note: required because of the requirements on the impl of `IntoOptPropValue<yew::Callback<FocusEvent>>` for `Option<{integer}>`
|
= help: the following implementations were found:
|
||||||
|
<Option<&'static str> as IntoPropValue<Option<Cow<'static, str>>>>
|
||||||
|
<Option<&'static str> as IntoPropValue<Option<String>>>
|
||||||
|
<Option<String> as IntoPropValue<Option<Cow<'static, str>>>>
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/element-fail.rs:56:24
|
--> $DIR/element-fail.rs:56:24
|
||||||
|
|||||||
@ -70,9 +70,9 @@ error[E0277]: `()` is not an iterator
|
|||||||
18 | { for () }
|
18 | { for () }
|
||||||
| ^^ `()` is not an iterator
|
| ^^ `()` is not an iterator
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/packages/yew/src/utils.rs
|
::: $WORKSPACE/packages/yew/src/utils.rs:50:9
|
||||||
|
|
|
|
||||||
| IT: IntoIterator<Item = T>,
|
50 | IT: IntoIterator<Item = T>,
|
||||||
| ---------------------- required by this bound in `into_node_iter`
|
| ---------------------- required by this bound in `into_node_iter`
|
||||||
|
|
|
|
||||||
= help: the trait `Iterator` is not implemented for `()`
|
= help: the trait `Iterator` is not implemented for `()`
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use super::{IntoOptPropValue, IntoPropValue};
|
use super::IntoPropValue;
|
||||||
use crate::virtual_dom::AttrValue;
|
use crate::virtual_dom::AttrValue;
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
use std::{
|
use std::{
|
||||||
@ -74,8 +74,8 @@ impl IntoPropValue<AttrValue> for Classes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoOptPropValue<AttrValue> for Classes {
|
impl IntoPropValue<Option<AttrValue>> for Classes {
|
||||||
fn into_opt_prop_value(self) -> Option<AttrValue> {
|
fn into_prop_value(self) -> Option<AttrValue> {
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -58,15 +58,15 @@ macro_rules! impl_into_prop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// implement V -> Option<T>
|
// implement V -> Option<T>
|
||||||
impl IntoOptPropValue<$to_ty> for $from_ty {
|
impl IntoPropValue<Option<$to_ty>> for $from_ty {
|
||||||
fn into_opt_prop_value(self) -> Option<$to_ty> {
|
fn into_prop_value(self) -> Option<$to_ty> {
|
||||||
let $value = self;
|
let $value = self;
|
||||||
Some({ $conversion })
|
Some({ $conversion })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// implement Option<V> -> Option<T>
|
// implement Option<V> -> Option<T>
|
||||||
impl IntoOptPropValue<$to_ty> for Option<$from_ty> {
|
impl IntoPropValue<Option<$to_ty>> for Option<$from_ty> {
|
||||||
fn into_opt_prop_value(self) -> Option<$to_ty> {
|
fn into_prop_value(self) -> Option<$to_ty> {
|
||||||
self.map(IntoPropValue::into_prop_value)
|
self.map(IntoPropValue::into_prop_value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,17 +79,15 @@ impl_into_prop!(|value: &'static str| -> String { value.to_owned() });
|
|||||||
impl_into_prop!(|value: &'static str| -> Cow<'static, str> { Cow::Borrowed(value) });
|
impl_into_prop!(|value: &'static str| -> Cow<'static, str> { Cow::Borrowed(value) });
|
||||||
impl_into_prop!(|value: String| -> Cow<'static, str> { Cow::Owned(value) });
|
impl_into_prop!(|value: String| -> Cow<'static, str> { Cow::Owned(value) });
|
||||||
|
|
||||||
/// A trait similar to `Into<Option<T>>` which allows conversion to an optional value of a
|
#[cfg(test)]
|
||||||
/// `Properties` struct.
|
mod test {
|
||||||
pub trait IntoOptPropValue<T> {
|
use super::*;
|
||||||
/// Convert `self` to an optional value of a `Properties` struct.
|
|
||||||
fn into_opt_prop_value(self) -> Option<T>;
|
#[test]
|
||||||
}
|
fn test_str() {
|
||||||
impl<T, V> IntoOptPropValue<V> for T
|
let _: String = "foo".into_prop_value();
|
||||||
where
|
let _: Option<String> = "foo".into_prop_value();
|
||||||
T: IntoPropValue<Option<V>>,
|
let _: Cow<'static, str> = "foo".into_prop_value();
|
||||||
{
|
let _: Option<Cow<'static, str>> = "foo".into_prop_value();
|
||||||
fn into_opt_prop_value(self) -> Option<V> {
|
|
||||||
self.into_prop_value()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ macro_rules! impl_action {
|
|||||||
pub mod $action {
|
pub mod $action {
|
||||||
use crate::callback::Callback;
|
use crate::callback::Callback;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use crate::html::{listener::*, IntoOptPropValue};
|
use crate::html::{listener::*, IntoPropValue};
|
||||||
use crate::virtual_dom::Listener;
|
use crate::virtual_dom::Listener;
|
||||||
use gloo::events::{EventListener, EventListenerOptions};
|
use gloo::events::{EventListener, EventListenerOptions};
|
||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::JsValue;
|
||||||
@ -26,8 +26,8 @@ macro_rules! impl_action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn __macro_new(callback: impl IntoOptPropValue<Callback<Event>>) -> Option<Rc<dyn Listener>> {
|
pub fn __macro_new(callback: impl IntoPropValue<Option<Callback<Event>>>) -> Option<Rc<dyn Listener>> {
|
||||||
let callback = callback.into_opt_prop_value()?;
|
let callback = callback.into_prop_value()?;
|
||||||
Some(Rc::new(Self::new(callback)))
|
Some(Rc::new(Self::new(callback)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ pub mod vtag;
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod vtext;
|
pub mod vtext;
|
||||||
|
|
||||||
use crate::html::{AnyScope, IntoOptPropValue, NodeRef};
|
use crate::html::{AnyScope, IntoPropValue, NodeRef};
|
||||||
use gloo::events::EventListener;
|
use gloo::events::EventListener;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use std::{borrow::Cow, collections::HashMap, fmt, hint::unreachable_unchecked, iter, mem, rc::Rc};
|
use std::{borrow::Cow, collections::HashMap, fmt, hint::unreachable_unchecked, iter, mem, rc::Rc};
|
||||||
@ -58,8 +58,8 @@ pub type AttrValue = Cow<'static, str>;
|
|||||||
pub struct PositionalAttr(pub &'static str, pub Option<AttrValue>);
|
pub struct PositionalAttr(pub &'static str, pub Option<AttrValue>);
|
||||||
impl PositionalAttr {
|
impl PositionalAttr {
|
||||||
/// Create a positional attribute
|
/// Create a positional attribute
|
||||||
pub fn new(key: &'static str, value: impl IntoOptPropValue<AttrValue>) -> Self {
|
pub fn new(key: &'static str, value: impl IntoPropValue<Option<AttrValue>>) -> Self {
|
||||||
Self(key, value.into_opt_prop_value())
|
Self(key, value.into_prop_value())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a boolean attribute.
|
/// Create a boolean attribute.
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
use super::{
|
use super::{
|
||||||
AttrValue, Attributes, Key, Listener, Listeners, Patch, PositionalAttr, VDiff, VList, VNode,
|
AttrValue, Attributes, Key, Listener, Listeners, Patch, PositionalAttr, VDiff, VList, VNode,
|
||||||
};
|
};
|
||||||
use crate::html::{AnyScope, IntoOptPropValue, IntoPropValue, NodeRef};
|
use crate::html::{AnyScope, IntoPropValue, NodeRef};
|
||||||
use crate::utils::document;
|
use crate::utils::document;
|
||||||
use gloo::events::EventListener;
|
use gloo::events::EventListener;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
@ -140,15 +140,15 @@ impl VTag {
|
|||||||
|
|
||||||
/// Sets `value` for an
|
/// Sets `value` for an
|
||||||
/// [InputElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
|
/// [InputElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
|
||||||
pub fn set_value(&mut self, value: impl IntoOptPropValue<AttrValue>) {
|
pub fn set_value(&mut self, value: impl IntoPropValue<Option<AttrValue>>) {
|
||||||
self.value = value.into_opt_prop_value();
|
self.value = value.into_prop_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets `kind` property of an
|
/// Sets `kind` property of an
|
||||||
/// [InputElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
|
/// [InputElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
|
||||||
/// Same as set `type` attribute.
|
/// Same as set `type` attribute.
|
||||||
pub fn set_kind(&mut self, value: impl IntoOptPropValue<AttrValue>) {
|
pub fn set_kind(&mut self, value: impl IntoPropValue<Option<AttrValue>>) {
|
||||||
self.kind = value.into_opt_prop_value();
|
self.kind = value.into_prop_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user