Skip to content

Commit

Permalink
feat(react): allow unsized WrapFn in html common props
Browse files Browse the repository at this point in the history
  • Loading branch information
EqualMa committed Feb 28, 2022
1 parent 62b7b25 commit 44a5cce
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/react-html/src/macros/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ macro_rules! __impl_prop_default {
{ event_handler }
) => {
$($attr)*
fn $k <F, A> (mut self, event_handler: Option<react::WrapFn<F, A>>) -> Self
fn $k <F: ?Sized, A> (mut self, event_handler: Option<react::WrapFn<F, A>>) -> Self
where react::WrapFn<F, A>: react::event::IntoJsEventHandler<$v_ty>
{
if let Some(event_handler) = event_handler {
Expand Down
4 changes: 2 additions & 2 deletions crates/react/src/event/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ pub trait IntoJsEventHandler<TEvent> {
}

/// `Fn()` can be handlers for any event
impl<F: 'static + Fn(), TEvent> IntoJsEventHandler<TEvent> for crate::WrapFn<F, ()> {
impl<F: 'static + ?Sized + Fn(), TEvent> IntoJsEventHandler<TEvent> for crate::WrapFn<F, ()> {
fn into_js_event_handler(self) -> crate::PassedToJsRuntime {
self.safe_into_js_runtime()
}
}

/// `Fn(TEvent)` can be handlers for `TEvent`
impl<F: 'static + Fn(TEvent), TEvent: FromJs> IntoJsEventHandler<TEvent>
impl<F: 'static + ?Sized + Fn(TEvent), TEvent: FromJs> IntoJsEventHandler<TEvent>
for crate::WrapFn<F, (TEvent,)>
where
TEvent::Error: std::fmt::Debug,
Expand Down
2 changes: 1 addition & 1 deletion crates/react/src/safe_into_js/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ macro_rules! doit {
($($var:ident)*)
)*) => ($(
#[doc = concat!("WrapFn<TFunc: Fn(", $(stringify!($var), ", ",)* ") -> TR>")]
impl<TFunc, $($var,)* R> SafeIntoJsRuntime for WrapFn<TFunc, ($($var,)*)>
impl<TFunc: ?Sized, $($var,)* R> SafeIntoJsRuntime for WrapFn<TFunc, ($($var,)*)>
where $($var: 'static,)*
R: 'static,
TFunc: Fn($($var),*) -> R + 'static,
Expand Down

0 comments on commit 44a5cce

Please sign in to comment.