From 1e5f5ecf8bb5072331fcd8ad10bec333d509777d Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 29 Dec 2019 01:21:10 +0900 Subject: [PATCH] Update autoreload example to v2 --- examples/autoreload/Cargo.toml | 3 ++- examples/autoreload/src/main.rs | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/autoreload/Cargo.toml b/examples/autoreload/Cargo.toml index 55b4b62..1561236 100644 --- a/examples/autoreload/Cargo.toml +++ b/examples/autoreload/Cargo.toml @@ -4,5 +4,6 @@ version = "1.0.0" edition = "2018" [dependencies] -actix-web = "1.0" +actix-web = "2.0" +actix-rt = "1.0" listenfd = "0.3" diff --git a/examples/autoreload/src/main.rs b/examples/autoreload/src/main.rs index 42ed302..3ceff63 100644 --- a/examples/autoreload/src/main.rs +++ b/examples/autoreload/src/main.rs @@ -2,20 +2,21 @@ use actix_web::{web, App, HttpRequest, HttpServer, Responder}; use listenfd::ListenFd; -fn index(_req: HttpRequest) -> impl Responder { +async fn index(_req: HttpRequest) -> impl Responder { "Hello World!" } -fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { let mut listenfd = ListenFd::from_env(); let mut server = HttpServer::new(|| App::new().route("/", web::get().to(index))); server = if let Some(l) = listenfd.take_tcp_listener(0).unwrap() { - server.listen(l).unwrap() + server.listen(l)? } else { - server.bind("127.0.0.1:3000").unwrap() + server.bind("127.0.0.1:3000")? }; - server.run().unwrap(); + server.run().await } //