Skip to content

Commit

Permalink
Support F -> Option<Callback<_>> too.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbear committed Mar 27, 2022
1 parent 4167b2e commit d61e368
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/yew/src/html/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ impl<I, O, F> IntoPropValue<Callback<I, O>> for F
}
}

impl<I, O, F> IntoPropValue<Option<Callback<I, O>>> for F
where
F: 'static + Fn(I) -> O,
{
fn into_prop_value(self) -> Option<Callback<I, O>> {
Some(Callback::from(self))
}
}

impl<I, O, F> IntoPropValue<Option<Callback<I, O>>> for Option<F>
where
F: 'static + Fn(I) -> O,
Expand Down Expand Up @@ -134,8 +143,10 @@ mod test {
#[test]
fn test_callback() {
let _: Callback<String> = (|_: String| ()).into_prop_value();
let _: Option<Callback<String>> = (|_: String| ()).into_prop_value();
let _: Option<Callback<String>> = Some(|_: String| ()).into_prop_value();
let _: Callback<String, String> = (|s: String| s).into_prop_value();
let _: Option<Callback<String, String>> = (|s: String| s).into_prop_value();
let _: Option<Callback<String, String>> = Some(|s: String| s).into_prop_value();
}
}

0 comments on commit d61e368

Please sign in to comment.