aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-06-02 17:28:26 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-06-02 17:28:26 +0200
commitdeced08513e9971eeb4165a5c27139e4d9a8daf3 (patch)
treee7b48358bd3bca7619e18ae4e06579f0c587497b
parent3370760891d05ded9ec5fabac634f5c08ef6ba46 (diff)
downloadaerogramme-deced08513e9971eeb4165a5c27139e4d9a8daf3.tar.gz
aerogramme-deced08513e9971eeb4165a5c27139e4d9a8daf3.zip
Replace with async
-rw-r--r--src/server.rs42
1 files changed, 13 insertions, 29 deletions
diff --git a/src/server.rs b/src/server.rs
index 81ffcd5..b06299c 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -23,14 +23,8 @@ pub struct Server {
pub login_provider: Box<dyn LoginProvider>,
}
-async fn handle_req(req: Request) -> Result<Response> {
- tracing::debug!("Got request: {:#?}", req);
- Ok(Response::ok("Done")?)
-}
-
-
-struct Echo;
-impl Service<Request> for Echo {
+struct Connection;
+impl Service<Request> for Connection {
type Response = Response;
type Error = anyhow::Error;
type Future = Pin<Box<dyn futures::Future<Output = Result<Self::Response>> + Send>>;
@@ -40,15 +34,16 @@ impl Service<Request> for Echo {
}
fn call(&mut self, req: Request) -> Self::Future {
- println!("Got request: {:#?}", req);
- let fut = futures::future::ok(Response::ok("Done").unwrap());
- Box::pin(fut)
+ Box::pin(async move {
+ println!("Got request: {:#?}", req);
+ Ok(Response::ok("Done")?)
+ })
}
}
-struct Charlie;
-impl<'a> Service<&'a AddrStream> for Charlie {
- type Response = Echo;
+struct Instance;
+impl<'a> Service<&'a AddrStream> for Instance {
+ type Response = Connection;
type Error = anyhow::Error;
type Future = Pin<Box<dyn futures::Future<Output = Result<Self::Response>> + Send>>;
@@ -58,8 +53,9 @@ impl<'a> Service<&'a AddrStream> for Charlie {
fn call(&mut self, addr: &'a AddrStream) -> Self::Future {
println!("{}, {}", addr.remote_addr, addr.local_addr);
- let fut = futures::future::ok(Echo);
- Box::pin(fut)
+ Box::pin(async {
+ Ok(Connection)
+ })
}
}
@@ -88,19 +84,7 @@ impl Server {
let incoming = AddrIncoming::new("127.0.0.1:4567").await?;
-
- /*let make_service = tower::service_fn(|addr: &AddrStream| {
- tracing::debug!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept");
- //let service = tower::ServiceBuilder::new().service_fn(handle_req);
- //let service = tower::service_fn(handle_req);
- let service = Echo;
- futures::future::ok::<_, std::convert::Infallible>(service)
- //service
- });*/
-
-
- //println!("{:?}", make_service);
- let server = ImapServer::new(incoming).serve(Charlie);
+ let server = ImapServer::new(incoming).serve(Instance);
let _ = server.await?;
/*let creds = self.login_provider.login("quentin", "poupou").await?;