Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn repl(mut state: CommandState, dispatcher: Handler<'static, Store, Comma
}
}

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CommandState {
Active,
Paused,
Expand Down
29 changes: 8 additions & 21 deletions src/handler/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DynF<'a, Input, Output> =

/// A continuation representing the rest of a handler chain.
pub type Cont<'a, Input, Output> =
Box<dyn Fn(Input) -> HandlerResult<'a, Input, Output> + Send + Sync + 'a>;
Box<dyn FnOnce(Input) -> HandlerResult<'a, Input, Output> + Send + Sync + 'a>;

/// An output type produced by a handler.
pub type HandlerResult<'a, Input, Output> = BoxFuture<'a, ControlFlow<Output, Input>>;
Expand Down Expand Up @@ -75,15 +75,8 @@ where
from_fn_with_description(required_update_kinds_set, move |event, cont| {
let this = self.clone();
let next = next.clone();
let cont = Arc::new(cont);

this.execute(event, move |event| {
let next = next.clone();
let cont = cont.clone();

#[allow(clippy::redundant_closure)] // Clippy is a fucking donkey.
next.execute(event, move |event| cont(event))
})
this.execute(event, |event| next.execute(event, cont))
})
}

Expand Down Expand Up @@ -132,17 +125,11 @@ where
from_fn_with_description(required_update_kinds_set, move |event, cont| {
let this = self.clone();
let next = next.clone();
let cont = Arc::new(cont);

this.execute(event, move |event| {
let next = next.clone();
let cont = cont.clone();

async move {
match next.dispatch(event).await {
ControlFlow::Continue(event) => cont(event).await,
done => done,
}
this.execute(event, |event| async move {
match next.dispatch(event).await {
ControlFlow::Continue(event) => cont(event).await,
done => done,
}
})
})
Expand Down Expand Up @@ -174,11 +161,11 @@ where
cont: Cont,
) -> ControlFlow<Output, Input>
where
Cont: Fn(Input) -> ContFut,
Cont: FnOnce(Input) -> ContFut,
Cont: Send + Sync + 'a,
ContFut: Future<Output = ControlFlow<Output, Input>> + Send + 'a,
{
(self.data.f)(container, Box::new(move |event| Box::pin(cont(event)))).await
(self.data.f)(container, Box::new(|event| Box::pin(cont(event)))).await
}

/// Executes this handler.
Expand Down