1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-18 05:41:50 +01:00

update examples

This commit is contained in:
Nikolay Kim 2019-11-26 17:16:33 +06:00
parent f73f97353b
commit f2b3dc5625
4 changed files with 27 additions and 23 deletions

View File

@ -33,10 +33,12 @@ async fn index(info: web::Path<(u32, String)>) -> impl Responder {
format!("Hello {}! id:{}", info.1, info.0) 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)) HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")? .bind("127.0.0.1:8080")?
.run() .start()
.await
} }
``` ```

View File

@ -16,7 +16,8 @@ async fn no_params() -> &'static str {
"Hello world!\r\n" "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"); std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init(); env_logger::init();
@ -41,5 +42,6 @@ fn main() -> std::io::Result<()> {
}) })
.bind("127.0.0.1:8080")? .bind("127.0.0.1:8080")?
.workers(1) .workers(1)
.run() .start()
.await
} }

View File

@ -1,11 +1,10 @@
use actix_http::Error; 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"); std::env::set_var("RUST_LOG", "actix_http=trace");
env_logger::init(); 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 // Create request builder, configure request and send
@ -23,5 +22,4 @@ fn main() -> Result<(), Error> {
println!("Downloaded: {:?} bytes", body.len()); println!("Downloaded: {:?} bytes", body.len());
Ok(()) Ok(())
})
} }

View File

@ -19,7 +19,8 @@ async fn no_params() -> &'static str {
} }
#[cfg(unix)] #[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"); std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init(); env_logger::init();
@ -44,7 +45,8 @@ fn main() -> std::io::Result<()> {
}) })
.bind_uds("/Users/fafhrd91/uds-test")? .bind_uds("/Users/fafhrd91/uds-test")?
.workers(1) .workers(1)
.run() .start()
.await
} }
#[cfg(not(unix))] #[cfg(not(unix))]