diff --git a/README.md b/README.md index 4c0553e38..b7a1bf28f 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,12 @@ async fn index(info: web::Path<(u32, String)>) -> impl Responder { format!("Hello {}! id:{}", info.1, info.0) } -fn main() -> std::io::Result<()> { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| App::new().service(index)) .bind("127.0.0.1:8080")? - .run() + .start() + .await } ``` diff --git a/examples/basic.rs b/examples/basic.rs index 6d9a4dcd8..b5b69fce2 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -16,7 +16,8 @@ async fn no_params() -> &'static str { "Hello world!\r\n" } -fn main() -> std::io::Result<()> { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); env_logger::init(); @@ -41,5 +42,6 @@ fn main() -> std::io::Result<()> { }) .bind("127.0.0.1:8080")? .workers(1) - .run() + .start() + .await } diff --git a/examples/client.rs b/examples/client.rs index 90a362fe3..874e08e1b 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -1,27 +1,25 @@ use actix_http::Error; -use actix_rt::System; -fn main() -> Result<(), Error> { +#[actix_rt::main] +async fn main() -> Result<(), Error> { std::env::set_var("RUST_LOG", "actix_http=trace"); env_logger::init(); - System::new("test").block_on(async { - let client = awc::Client::new(); + let client = awc::Client::new(); - // Create request builder, configure request and send - let mut response = client - .get("https://www.rust-lang.org/") - .header("User-Agent", "Actix-web") - .send() - .await?; + // Create request builder, configure request and send + let mut response = client + .get("https://www.rust-lang.org/") + .header("User-Agent", "Actix-web") + .send() + .await?; - // server http response - println!("Response: {:?}", response); + // server http response + println!("Response: {:?}", response); - // read response body - let body = response.body().await?; - println!("Downloaded: {:?} bytes", body.len()); + // read response body + let body = response.body().await?; + println!("Downloaded: {:?} bytes", body.len()); - Ok(()) - }) + Ok(()) } diff --git a/examples/uds.rs b/examples/uds.rs index fc6a58de1..8db4cf230 100644 --- a/examples/uds.rs +++ b/examples/uds.rs @@ -19,7 +19,8 @@ async fn no_params() -> &'static str { } #[cfg(unix)] -fn main() -> std::io::Result<()> { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); env_logger::init(); @@ -44,7 +45,8 @@ fn main() -> std::io::Result<()> { }) .bind_uds("/Users/fafhrd91/uds-test")? .workers(1) - .run() + .start() + .await } #[cfg(not(unix))]