From beef863f9f93857cef79652886afa2d0accfcd35 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 10 Jul 2022 18:18:40 +0400 Subject: [PATCH 1/4] Make continuation `FnOnce` --- src/handler/core.rs | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/handler/core.rs b/src/handler/core.rs index ddad938..238b44a 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,14 +75,10 @@ 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(); + this.execute(event, |event| { #[allow(clippy::redundant_closure)] // Clippy is a fucking donkey. - next.execute(event, move |event| cont(event)) + next.execute(event, |event| cont(event)) }) }) } @@ -132,17 +128,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 +164,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. From f690555655e211bcdfc4deb7fb2dbb7f22b520b8 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 10 Jul 2022 18:19:57 +0400 Subject: [PATCH 2/4] Remove outdated clippy allow --- src/handler/core.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/handler/core.rs b/src/handler/core.rs index 238b44a..f16066c 100644 --- a/src/handler/core.rs +++ b/src/handler/core.rs @@ -76,10 +76,7 @@ where let this = self.clone(); let next = next.clone(); - this.execute(event, |event| { - #[allow(clippy::redundant_closure)] // Clippy is a fucking donkey. - next.execute(event, |event| cont(event)) - }) + this.execute(event, |event| next.execute(event, cont)) }) } From 9aa350cf8fef005f3c0b130ec745e8db78c50690 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 10 Jul 2022 18:20:26 +0400 Subject: [PATCH 3/4] Fix clippy --- examples/state_machine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 99402f15fcb38f585c708dd212cd6b9d4fe308fb Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 18 Jul 2022 14:52:31 +0400 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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