1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 22:49:21 +02:00

rename .to_async() to .to()

This commit is contained in:
Nikolay Kim
2019-11-21 21:34:04 +06:00
parent 0b9e3d381b
commit 8683ba8bb0
25 changed files with 232 additions and 396 deletions

View File

@ -1,9 +1,7 @@
use actix_web::{
get, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer,
};
use actix_web::{get, middleware, web, App, HttpRequest, HttpResponse, HttpServer};
#[get("/resource1/{name}/index.html")]
fn index(req: HttpRequest, name: web::Path<String>) -> String {
async fn index(req: HttpRequest, name: web::Path<String>) -> String {
println!("REQ: {:?}", req);
format!("Hello: {}!\r\n", name)
}
@ -14,7 +12,7 @@ async fn index_async(req: HttpRequest) -> &'static str {
}
#[get("/")]
fn no_params() -> &'static str {
async fn no_params() -> &'static str {
"Hello world!\r\n"
}
@ -37,9 +35,9 @@ fn main() -> std::io::Result<()> {
.default_service(
web::route().to(|| HttpResponse::MethodNotAllowed()),
)
.route(web::get().to_async(index_async)),
.route(web::get().to(index_async)),
)
.service(web::resource("/test1.html").to(|| "Test\r\n"))
.service(web::resource("/test1.html").to(|| async { "Test\r\n" }))
})
.bind("127.0.0.1:8080")?
.workers(1)

View File

@ -3,7 +3,7 @@ use actix_web::{
};
#[get("/resource1/{name}/index.html")]
fn index(req: HttpRequest, name: web::Path<String>) -> String {
async fn index(req: HttpRequest, name: web::Path<String>) -> String {
println!("REQ: {:?}", req);
format!("Hello: {}!\r\n", name)
}
@ -14,11 +14,11 @@ async fn index_async(req: HttpRequest) -> Result<&'static str, Error> {
}
#[get("/")]
fn no_params() -> &'static str {
async fn no_params() -> &'static str {
"Hello world!\r\n"
}
#[cfg(feature = "uds")]
#[cfg(unix)]
fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init();
@ -27,7 +27,7 @@ fn main() -> std::io::Result<()> {
App::new()
.wrap(middleware::DefaultHeaders::new().header("X-Version", "0.2"))
.wrap(middleware::Compress::default())
// .wrap(middleware::Logger::default())
.wrap(middleware::Logger::default())
.service(index)
.service(no_params)
.service(
@ -36,16 +36,16 @@ fn main() -> std::io::Result<()> {
middleware::DefaultHeaders::new().header("X-Version-R2", "0.3"),
)
.default_service(
web::route().to(|| ok(HttpResponse::MethodNotAllowed())),
web::route().to(|| HttpResponse::MethodNotAllowed()),
)
.route(web::get().to_async(index_async)),
.route(web::get().to(index_async)),
)
.service(web::resource("/test1.html").to(|| "Test\r\n"))
.service(web::resource("/test1.html").to(|| async { "Test\r\n" }))
})
.bind_uds("/Users/fafhrd91/uds-test")?
.workers(1)
.run()
}
#[cfg(not(feature = "uds"))]
#[cfg(not(unix))]
fn main() {}