diff --git a/examples/responder-trait/Cargo.toml b/examples/responder-trait/Cargo.toml index 565cd46..46bb4bf 100644 --- a/examples/responder-trait/Cargo.toml +++ b/examples/responder-trait/Cargo.toml @@ -4,6 +4,8 @@ version = "1.0.0" edition = "2018" [dependencies] -actix-web = "1.0" +actix-web = "2.0" +actix-rt = "1.0" +futures = "0.3.1" serde = "1.0" serde_json = "1.0" diff --git a/examples/responder-trait/src/main.rs b/examples/responder-trait/src/main.rs index 5b199b3..972e6c2 100644 --- a/examples/responder-trait/src/main.rs +++ b/examples/responder-trait/src/main.rs @@ -1,6 +1,7 @@ // use actix_web::{Error, HttpRequest, HttpResponse, Responder}; use serde::Serialize; +use futures::future::{ready, Ready}; #[derive(Serialize)] struct MyObj { @@ -10,29 +11,29 @@ struct MyObj { // Responder impl Responder for MyObj { type Error = Error; - type Future = Result; + type Future = Ready>; fn respond_to(self, _req: &HttpRequest) -> Self::Future { - let body = serde_json::to_string(&self)?; + let body = serde_json::to_string(&self).unwrap(); // Create response and set content type - Ok(HttpResponse::Ok() + ready(Ok(HttpResponse::Ok() .content_type("application/json") - .body(body)) + .body(body))) } } -fn index() -> impl Responder { +async fn index() -> impl Responder { MyObj { name: "user" } } // -fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| App::new().route("/", web::get().to(index))) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await }