Skip to content

Commit

Permalink
attempt to fix inference
Browse files Browse the repository at this point in the history
  • Loading branch information
kmicklas committed Jun 21, 2024
1 parent 94f0033 commit 905ef4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/tutorial/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn events() -> View!(Model) {
"Message: ",
// [`on`], unlike [`on_`], also gives us access to the underlying
// [`web_sys::Event`].
el::input(on(event::InputEvent, |model: &mut Model, event| {
el::input(on(event::InputEvent, |model: &mut _, event| {
model.message = event
.target()
.unwrap_throw()
Expand Down
22 changes: 13 additions & 9 deletions ravel-web/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ impl<K: EventKind> EventKind for Active<K> {
}

/// An event handler.
pub struct On<Kind: EventKind, Action> {
pub struct On<Kind: EventKind, Action, Output> {
action: Action,
kind: PhantomData<Kind>,
kind: PhantomData<(Kind, Output)>,
}

impl<Kind: EventKind, Action: 'static> Builder<Web> for On<Kind, Action> {
type State = OnState<Action>;
impl<Kind: EventKind, Action: 'static, Output> Builder<Web>
for On<Kind, Action, Output>
{
type State = OnState<Action, Output>;

fn build(self, cx: BuildCx) -> Self::State {
let waker = cx.position.waker.clone();
Expand All @@ -58,6 +60,7 @@ impl<Kind: EventKind, Action: 'static> Builder<Web> for On<Kind, Action> {
},
),
action: self.action,
phantom: PhantomData,
}
}

Expand All @@ -67,14 +70,15 @@ impl<Kind: EventKind, Action: 'static> Builder<Web> for On<Kind, Action> {
}

/// The state of an [`On`].
pub struct OnState<Action> {
pub struct OnState<Action, Output> {
event: EventCell,
_handle: gloo_events::EventListener,
action: Action,
phantom: PhantomData<Output>,
}

impl<Action: 'static + FnMut(&mut Output, web_sys::Event), Output: 'static>
State<Output> for OnState<Action>
State<Output> for OnState<Action, Output>
{
fn run(&mut self, output: &mut Output) {
let event = self.event.take();
Expand All @@ -92,7 +96,7 @@ pub fn on<
>(
_: Kind,
action: Action,
) -> On<Kind, Action> {
) -> On<Kind, Action, Output> {
On {
action,
kind: PhantomData,
Expand All @@ -107,9 +111,9 @@ pub fn on_<
>(
_: Kind,
mut action: Action,
) -> On<Kind, impl 'static + FnMut(&mut Output, web_sys::Event)> {
) -> On<Kind, impl 'static + FnMut(&mut Output, web_sys::Event), Output> {
On {
action: move |o: &mut _, _: _| action(o),
action: move |o: &mut _, _| action(o),
kind: PhantomData,
}
}
Expand Down

0 comments on commit 905ef4e

Please sign in to comment.