Skip to content

Commit 80183bb

Browse files
committed
Use async fn instead of fn() -> impl Future in struct methods
1 parent b7c9ed4 commit 80183bb

File tree

2 files changed

+39
-42
lines changed

2 files changed

+39
-42
lines changed

src/core/app/mod.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{future::Future, marker::PhantomData, sync::Arc};
1+
use std::{marker::PhantomData, sync::Arc};
22

33
use crate::{
44
core::{
@@ -49,25 +49,23 @@ where
4949
}
5050
}
5151

52-
fn handle_update(&self, update: Update) -> impl Future<Output = ()> + use<H, HI, HO> {
52+
async fn handle_update(&self, update: Update) -> () {
5353
let input = HandlerInput {
5454
update,
5555
context: self.context.clone(),
5656
};
5757
let handler = self.handler.clone();
58-
async move {
59-
let input = match HI::try_from_input(input).await {
60-
Ok(Some(input)) => input,
61-
Ok(None) => return,
62-
Err(err) => {
63-
log::error!("Failed to convert input: {}", err);
64-
return;
65-
}
66-
};
67-
let future = handler.handle(input);
68-
if let Err(err) = future.await.into_result() {
69-
log::error!("An error has occurred: {}", err);
58+
let input = match HI::try_from_input(input).await {
59+
Ok(Some(input)) => input,
60+
Ok(None) => return,
61+
Err(err) => {
62+
log::error!("Failed to convert input: {}", err);
63+
return;
7064
}
65+
};
66+
let future = handler.handle(input);
67+
if let Err(err) = future.await.into_result() {
68+
log::error!("An error has occurred: {}", err);
7169
}
7270
}
7371
}

src/core/chain/mod.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{any::type_name, error::Error, future::Future, marker::PhantomData, sync::Arc};
1+
use std::{any::type_name, error::Error, marker::PhantomData, sync::Arc};
22

33
use futures_util::future::BoxFuture;
44

@@ -68,41 +68,40 @@ impl Chain {
6868
self
6969
}
7070

71-
fn handle_input(&self, input: HandlerInput) -> impl Future<Output = HandlerResult> + use<> {
71+
async fn handle_input(&self, input: HandlerInput) -> HandlerResult {
7272
let handlers = self.handlers.clone();
7373
let strategy = self.strategy;
74-
async move {
75-
for handler in handlers.iter() {
76-
let type_name = handler.get_type_name();
77-
log::debug!("Running '{}' handler...", type_name);
78-
let result = handler.handle(input.clone()).await;
79-
match result {
80-
ChainResult::Done(result) => match strategy {
81-
ChainStrategy::All => match result {
82-
Ok(()) => {
83-
log::debug!("[CONTINUE] Handler '{}' succeeded", type_name);
84-
}
85-
Err(err) => {
86-
log::debug!("[STOP] Handler '{}' returned an error: {}", type_name, err);
87-
return Err(err);
88-
}
89-
},
90-
ChainStrategy::FirstFound => {
91-
log::debug!("[STOP] First found handler: '{}'", type_name);
92-
return result;
74+
75+
for handler in handlers.iter() {
76+
let type_name = handler.get_type_name();
77+
log::debug!("Running '{}' handler...", type_name);
78+
let result = handler.handle(input.clone()).await;
79+
match result {
80+
ChainResult::Done(result) => match strategy {
81+
ChainStrategy::All => match result {
82+
Ok(()) => {
83+
log::debug!("[CONTINUE] Handler '{}' succeeded", type_name);
84+
}
85+
Err(err) => {
86+
log::debug!("[STOP] Handler '{}' returned an error: {}", type_name, err);
87+
return Err(err);
9388
}
9489
},
95-
ChainResult::Err(err) => {
96-
log::debug!("[STOP] Could not convert input for '{}' handler: {}", type_name, err);
97-
return Err(err);
98-
}
99-
ChainResult::Skipped => {
100-
log::debug!("[CONTINUE] Input not found for '{}' handler", type_name);
90+
ChainStrategy::FirstFound => {
91+
log::debug!("[STOP] First found handler: '{}'", type_name);
92+
return result;
10193
}
94+
},
95+
ChainResult::Err(err) => {
96+
log::debug!("[STOP] Could not convert input for '{}' handler: {}", type_name, err);
97+
return Err(err);
98+
}
99+
ChainResult::Skipped => {
100+
log::debug!("[CONTINUE] Input not found for '{}' handler", type_name);
102101
}
103102
}
104-
Ok(())
105103
}
104+
Ok(())
106105
}
107106
}
108107

0 commit comments

Comments
 (0)