diff --git a/examples/powerful-extractors/Cargo.toml b/examples/powerful-extractors/Cargo.toml index 5f20144..1e84b9e 100644 --- a/examples/powerful-extractors/Cargo.toml +++ b/examples/powerful-extractors/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/powerful-extractors/src/main.rs b/examples/powerful-extractors/src/main.rs index 5d80d7f..7005554 100644 --- a/examples/powerful-extractors/src/main.rs +++ b/examples/powerful-extractors/src/main.rs @@ -20,25 +20,25 @@ fn store_in_db(timestamp: f64, kind: &str, tags: &[String]) -> Event { } } -fn capture_event(evt: web::Json) -> impl Responder { +async fn capture_event(evt: web::Json) -> impl Responder { let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags); format!("got event {}", new_event.id.unwrap()) } -fn index() -> HttpResponse { +async fn index() -> HttpResponse { HttpResponse::Ok() .content_type("text/html; charset=utf-8") .body(include_str!("../static/form.html")) } -fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .route("/", web::get().to(index)) .route("/event", web::post().to(capture_event)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await }