Skip to content

Commit c307f07

Browse files
author
mc1098
authored
Fix IntoEventCallback over IntoPropValue (#2025)
PR #1542 didn't merge in the changes from #1989 correctly, this is fixed in this commit.
1 parent 7a55441 commit c307f07

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

packages/yew-macro/tests/html_macro/element-fail.stderr

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<Cow<'stat
302302
<Option<String> as IntoPropValue<Option<Cow<'static, str>>>>
303303
= note: required by `into_prop_value`
304304

305-
error[E0277]: the trait bound `{integer}: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
305+
error[E0277]: expected a `Fn<(MouseEvent,)>` closure, found `{integer}`
306306
--> $DIR/element-fail.rs:51:28
307307
|
308308
51 | html! { <input onclick=1 /> };
309-
| ^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `{integer}`
309+
| ^ expected an `Fn<(MouseEvent,)>` closure, found `{integer}`
310310
|
311311
::: $WORKSPACE/packages/yew/src/html/listener/events.rs
312312
|
@@ -319,18 +319,17 @@ error[E0277]: the trait bound `{integer}: IntoPropValue<Option<yew::Callback<Mou
319319
197 | | }
320320
| |_- required by this bound in `yew::html::onclick::Wrapper::__macro_new`
321321
|
322-
= help: the following implementations were found:
323-
<&'static str as IntoPropValue<Cow<'static, str>>>
324-
<&'static str as IntoPropValue<Option<Cow<'static, str>>>>
325-
<&'static str as IntoPropValue<Option<String>>>
326-
<&'static str as IntoPropValue<String>>
327-
and 11 others
322+
= help: the trait `Fn<(MouseEvent,)>` is not implemented for `{integer}`
323+
= note: required because of the requirements on the impl of `IntoEventCallback<MouseEvent>` for `{integer}`
328324

329-
error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
325+
error[E0277]: expected a `Fn<(MouseEvent,)>` closure, found `yew::Callback<String>`
330326
--> $DIR/element-fail.rs:52:29
331327
|
332328
52 | html! { <input onclick={Callback::from(|a: String| ())} /> };
333-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `yew::Callback<String>`
329+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
330+
| |
331+
| expected an implementor of trait `IntoEventCallback<MouseEvent>`
332+
| help: consider borrowing here: `&Callback::from(|a: String| ())`
334333
|
335334
::: $WORKSPACE/packages/yew/src/html/listener/events.rs
336335
|
@@ -342,12 +341,15 @@ error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::
342341
196 | | ontransitionstart(TransitionEvent)
343342
197 | | }
344343
| |_- required by this bound in `yew::html::onclick::Wrapper::__macro_new`
344+
|
345+
= note: the trait bound `yew::Callback<String>: IntoEventCallback<MouseEvent>` is not satisfied
346+
= note: required because of the requirements on the impl of `IntoEventCallback<MouseEvent>` for `yew::Callback<String>`
345347

346-
error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<yew::Callback<FocusEvent>>>` is not satisfied
348+
error[E0277]: the trait bound `Option<{integer}>: IntoEventCallback<FocusEvent>` is not satisfied
347349
--> $DIR/element-fail.rs:53:29
348350
|
349351
53 | html! { <input onfocus={Some(5)} /> };
350-
| ^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<FocusEvent>>>` is not implemented for `Option<{integer}>`
352+
| ^^^^^^^ the trait `IntoEventCallback<FocusEvent>` is not implemented for `Option<{integer}>`
351353
|
352354
::: $WORKSPACE/packages/yew/src/html/listener/events.rs
353355
|
@@ -361,9 +363,8 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<yew::Call
361363
| |_- required by this bound in `yew::html::onfocus::Wrapper::__macro_new`
362364
|
363365
= help: the following implementations were found:
364-
<Option<&'static str> as IntoPropValue<Option<Cow<'static, str>>>>
365-
<Option<&'static str> as IntoPropValue<Option<String>>>
366-
<Option<String> as IntoPropValue<Option<Cow<'static, str>>>>
366+
<Option<T> as IntoEventCallback<EVENT>>
367+
<Option<yew::Callback<EVENT>> as IntoEventCallback<EVENT>>
367368

368369
error[E0277]: the trait bound `(): IntoPropValue<yew::NodeRef>` is not satisfied
369370
--> $DIR/element-fail.rs:56:25
@@ -385,11 +386,14 @@ error[E0277]: the trait bound `Option<yew::NodeRef>: IntoPropValue<yew::NodeRef>
385386
<Option<String> as IntoPropValue<Option<Cow<'static, str>>>>
386387
= note: required by `into_prop_value`
387388

388-
error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not satisfied
389+
error[E0277]: expected a `Fn<(MouseEvent,)>` closure, found `yew::Callback<String>`
389390
--> $DIR/element-fail.rs:58:29
390391
|
391392
58 | html! { <input onclick={Callback::from(|a: String| ())} /> };
392-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoPropValue<Option<yew::Callback<MouseEvent>>>` is not implemented for `yew::Callback<String>`
393+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
394+
| |
395+
| expected an implementor of trait `IntoEventCallback<MouseEvent>`
396+
| help: consider borrowing here: `&Callback::from(|a: String| ())`
393397
|
394398
::: $WORKSPACE/packages/yew/src/html/listener/events.rs
395399
|
@@ -401,6 +405,9 @@ error[E0277]: the trait bound `yew::Callback<String>: IntoPropValue<Option<yew::
401405
196 | | ontransitionstart(TransitionEvent)
402406
197 | | }
403407
| |_- required by this bound in `yew::html::onclick::Wrapper::__macro_new`
408+
|
409+
= note: the trait bound `yew::Callback<String>: IntoEventCallback<MouseEvent>` is not satisfied
410+
= note: required because of the requirements on the impl of `IntoEventCallback<MouseEvent>` for `yew::Callback<String>`
404411

405412
error[E0277]: the trait bound `NotToString: IntoPropValue<Option<Cow<'static, str>>>` is not satisfied
406413
--> $DIR/element-fail.rs:60:28

packages/yew/src/html/listener/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ macro_rules! impl_action {
2727
#[doc(hidden)]
2828
#[inline]
2929
pub fn __macro_new(
30-
callback: impl crate::html::IntoPropValue<Option<Callback<Event>>>,
30+
callback: impl crate::html::IntoEventCallback<Event>,
3131
) -> Option<Rc<dyn Listener>> {
32-
let callback = callback.into_prop_value()?;
32+
let callback = callback.into_event_callback()?;
3333
Some(Rc::new(Self::new(callback)))
3434
}
3535
}

0 commit comments

Comments
 (0)