diff --git a/CHANGELOG.md b/CHANGELOG.md index 72bacfd..191dc12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Removed some useless bounds from methods +- `Cont` is now `FnOnce` instead of `Fn` ## 0.2.1 - 2022-04-27 diff --git a/examples/state_machine.rs b/examples/state_machine.rs index 8baf08d..0669593 100644 --- a/examples/state_machine.rs +++ b/examples/state_machine.rs @@ -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, diff --git a/src/handler/core.rs b/src/handler/core.rs index ddad938..f16066c 100644 --- a/src/handler/core.rs +++ b/src/handler/core.rs @@ -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 HandlerResult<'a, Input, Output> + Send + Sync + 'a>; + Box HandlerResult<'a, Input, Output> + Send + Sync + 'a>; /// An output type produced by a handler. pub type HandlerResult<'a, Input, Output> = BoxFuture<'a, ControlFlow>; @@ -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)) }) } @@ -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, } }) }) @@ -174,11 +161,11 @@ where cont: Cont, ) -> ControlFlow where - Cont: Fn(Input) -> ContFut, + Cont: FnOnce(Input) -> ContFut, Cont: Send + Sync + 'a, ContFut: Future> + 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.