From 66c3bd87295c39e67f15a57adeb95d4bb1ec8c5d Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 29 Dec 2019 01:24:52 +0900 Subject: [PATCH] Update easu-form-handling example --- examples/easy-form-handling/Cargo.toml | 3 ++- examples/easy-form-handling/src/main.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/easy-form-handling/Cargo.toml b/examples/easy-form-handling/Cargo.toml index bbf8d22..1af8b96 100644 --- a/examples/easy-form-handling/Cargo.toml +++ b/examples/easy-form-handling/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" serde = "1.0" diff --git a/examples/easy-form-handling/src/main.rs b/examples/easy-form-handling/src/main.rs index 84f577a..1bc63f4 100644 --- a/examples/easy-form-handling/src/main.rs +++ b/examples/easy-form-handling/src/main.rs @@ -8,25 +8,25 @@ struct Register { country: String, } -fn index() -> HttpResponse { +async fn index() -> HttpResponse { HttpResponse::Ok() .content_type("text/html; charset=utf-8") .body(include_str!("../static/form.html")) } -fn register(form: web::Form) -> impl Responder { +async fn register(form: web::Form) -> impl Responder { format!("Hello {} from {}!", form.username, form.country) } -fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .route("/", web::get().to(index)) .route("/register", web::post().to(register)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } //