From 5133ab874df2a7075d8e781241a727e9012cb80e Mon Sep 17 00:00:00 2001 From: Cameron Dershem Date: Fri, 28 Jun 2019 13:31:30 -0400 Subject: [PATCH] Final fixes before requesting review. --- content/docs/application.md | 2 +- content/docs/errors.md | 2 +- content/docs/handlers.md | 6 +++--- content/docs/request.md | 4 +--- content/docs/url-dispatch.md | 2 +- examples/application/src/app.rs | 4 ++-- examples/async-handlers/src/async_stream.rs | 8 ++++---- examples/async-handlers/src/main.rs | 20 +++++++++++++------ examples/async-handlers/src/stream.rs | 6 ++++-- examples/either/src/main.rs | 12 ++++++++--- examples/errors/src/helpers.rs | 4 ++-- examples/errors/src/main.rs | 2 +- examples/errors/src/override_error.rs | 8 ++++---- examples/extractors/src/form.rs | 4 +++- examples/extractors/src/json_one.rs | 4 +++- examples/extractors/src/json_two.rs | 4 +++- examples/extractors/src/multiple.rs | 4 +++- examples/extractors/src/path_one.rs | 4 +++- examples/extractors/src/path_three.rs | 4 +++- examples/extractors/src/path_two.rs | 4 +++- examples/extractors/src/query.rs | 4 +++- examples/getting-started/src/main.rs | 4 ++-- examples/request-handlers/src/handlers_arc.rs | 4 +++- examples/request-handlers/src/main.rs | 4 +++- examples/responder-trait/src/main.rs | 4 +++- examples/responses/src/chunked.rs | 4 ++-- examples/responses/src/identity_two.rs | 5 ++--- examples/responses/src/main.rs | 3 +-- examples/static-files/src/main.rs | 4 +++- examples/url-dispatch/src/guard.rs | 6 +++--- examples/url-dispatch/src/minfo.rs | 6 +++--- examples/url-dispatch/src/norm.rs | 4 ++-- examples/url-dispatch/src/norm2.rs | 12 +++++------ examples/url-dispatch/src/path.rs | 4 ++-- examples/url-dispatch/src/path2.rs | 4 ++-- examples/url-dispatch/src/pbuf.rs | 4 ++-- examples/url-dispatch/src/scope.rs | 4 ++-- examples/url-dispatch/src/url_ext.rs | 4 ++-- examples/url-dispatch/src/urls.rs | 4 ++-- layouts/index.html | 1 - 40 files changed, 116 insertions(+), 81 deletions(-) diff --git a/content/docs/application.md b/content/docs/application.md index 9da0f0c..95df909 100644 --- a/content/docs/application.md +++ b/content/docs/application.md @@ -43,7 +43,7 @@ as the first application, it would match all incoming requests. ## State Application state is shared with all routes and resources within the same scope. State -can be accessed with `web::Data` as read-only, but interior mutability with +can be accessed with the `web::Data` extractor as read-only, but interior mutability with `Cell` can be used to achieve state mutability. State is also available for route matching guards and middlewares. diff --git a/content/docs/errors.md b/content/docs/errors.md index 25c30d1..50c5baf 100644 --- a/content/docs/errors.md +++ b/content/docs/errors.md @@ -40,7 +40,7 @@ converted into an `HttpInternalServerError`: ```rust use std::io; -fn index(req: &HttpRequest) -> io::Result { +fn index(_req: HttpRequest) -> io::Result { Ok(fs::NamedFile::open("static/index.html")?) } ``` diff --git a/content/docs/handlers.md b/content/docs/handlers.md index c571190..d67cb33 100644 --- a/content/docs/handlers.md +++ b/content/docs/handlers.md @@ -22,13 +22,13 @@ such as `&'static str`, `String`, etc. Examples of valid handlers: ```rust -fn index(req: &HttpRequest) -> &'static str { +fn index(_req: HttpRequest) -> &'static str { "Hello world!" } ``` ```rust -fn index(req: HttpRequest) -> String { +fn index(_req: HttpRequest) -> String { "Hello world!".to_owned() } ``` @@ -37,7 +37,7 @@ You can also change the signature to return `impl Responder` which works well if complex types are involved. ```rust -fn index(req: HttpRequest) -> impl Responder { +fn index(_req: HttpRequest) -> impl Responder { Bytes::from_static("Hello world!") } ``` diff --git a/content/docs/request.md b/content/docs/request.md index 4c93f0c..ad71c29 100644 --- a/content/docs/request.md +++ b/content/docs/request.md @@ -49,9 +49,7 @@ is decompressed. # Multipart body -Actix provides multipart stream support with an external crate, [`actix-multipart`][multipartcrate]. - -The following demonstrates multipart stream handling for a simple form: +Actix-web provides multipart stream support with an external crate, [`actix-multipart`][multipartcrate]. > A full example is available in the [examples directory][multipartexample]. diff --git a/content/docs/url-dispatch.md b/content/docs/url-dispatch.md index 0a0f5e3..c7f40e1 100644 --- a/content/docs/url-dispatch.md +++ b/content/docs/url-dispatch.md @@ -83,7 +83,7 @@ against a URL path pattern. `path` represents the path portion of the URL that w The way that *actix-web* does this is very simple. When a request enters the system, for each resource configuration declaration present in the system, actix checks the request's path against the pattern declared. This checking happens in the order that -the routes were declared via `App::resource()` method. If resource can not be found, +the routes were declared via `App::service()` method. If resource can not be found, the *default resource* is used as the matched resource. When a route configuration is declared, it may contain route guard arguments. All route diff --git a/examples/application/src/app.rs b/examples/application/src/app.rs index 1f53cd3..7dadc5c 100644 --- a/examples/application/src/app.rs +++ b/examples/application/src/app.rs @@ -1,7 +1,7 @@ // -use actix_web::{web, App, HttpRequest, Responder}; +use actix_web::{web, App, Responder}; -fn index(_req: HttpRequest) -> impl Responder { +fn index() -> impl Responder { "Hello world!" } diff --git a/examples/async-handlers/src/async_stream.rs b/examples/async-handlers/src/async_stream.rs index b954cb0..ddc6ad6 100644 --- a/examples/async-handlers/src/async_stream.rs +++ b/examples/async-handlers/src/async_stream.rs @@ -3,12 +3,10 @@ fn is_error() -> bool { } // -use actix_web::{error, web, App, Error, HttpRequest, HttpResponse, HttpServer}; +use actix_web::{error, Error, HttpResponse}; use futures::future::{result, Future}; -fn index( - _req: HttpRequest, -) -> Result>, Error> { +fn index() -> Result>, Error> { if is_error() { Err(error::ErrorBadRequest("bad request")) } else { @@ -20,6 +18,8 @@ fn index( // pub fn main() { + use actix_web::{web, App, HttpServer}; + HttpServer::new(|| App::new().route("/", web::to_async(index))) .bind("127.0.0.1:8088") .unwrap() diff --git a/examples/async-handlers/src/main.rs b/examples/async-handlers/src/main.rs index f86d286..05a4ff4 100644 --- a/examples/async-handlers/src/main.rs +++ b/examples/async-handlers/src/main.rs @@ -1,22 +1,30 @@ pub mod async_stream; pub mod stream; // -use actix_web::{web, App, Error, HttpRequest, HttpResponse}; +use actix_web::{Error, HttpResponse}; use futures::future::{ok, Future}; -fn index(_req: HttpRequest) -> Box> { +fn index() -> Box> { Box::new(ok::<_, Error>( HttpResponse::Ok().content_type("text/html").body("Hello!"), )) } -fn index2(_req: HttpRequest) -> Box> { +fn index2() -> Box> { Box::new(ok::<_, Error>("Welcome!")) } fn main() { - App::new() - .route("/async", web::to_async(index)) - .route("/", web::to_async(index2)); + use actix_web::{web, App, HttpServer}; + + HttpServer::new(|| { + App::new() + .route("/async", web::to_async(index)) + .route("/", web::to_async(index2)) + }) + .bind("127.0.0.1:8088") + .unwrap() + .run() + .unwrap(); } // diff --git a/examples/async-handlers/src/stream.rs b/examples/async-handlers/src/stream.rs index abcefb1..79424cd 100644 --- a/examples/async-handlers/src/stream.rs +++ b/examples/async-handlers/src/stream.rs @@ -1,9 +1,9 @@ // -use actix_web::{web, App, Error, HttpRequest, HttpResponse, HttpServer}; +use actix_web::{Error, HttpResponse}; use bytes::Bytes; use futures::stream::once; -fn index(_req: HttpRequest) -> HttpResponse { +fn index() -> HttpResponse { let body = once::(Ok(Bytes::from_static(b"test"))); HttpResponse::Ok() @@ -12,6 +12,8 @@ fn index(_req: HttpRequest) -> HttpResponse { } pub fn main() { + use actix_web::{web, App, HttpServer}; + HttpServer::new(|| App::new().route("/async", web::to_async(index))) .bind("127.0.0.1:8088") .unwrap() diff --git a/examples/either/src/main.rs b/examples/either/src/main.rs index 3ecd892..3c6af05 100644 --- a/examples/either/src/main.rs +++ b/examples/either/src/main.rs @@ -1,11 +1,11 @@ // -use actix_web::{web, App, Either, Error, HttpRequest, HttpResponse}; +use actix_web::{Either, Error, HttpResponse}; use futures::future::{ok, Future}; type RegisterResult = Either>>; -fn index(_req: HttpRequest) -> RegisterResult { +fn index() -> RegisterResult { if is_a_variant() { // <- choose variant A Either::A(HttpResponse::BadRequest().body("Bad data")) @@ -20,7 +20,13 @@ fn index(_req: HttpRequest) -> RegisterResult { } fn main() { - App::new().route("/", web::get().to(index)); + use actix_web::{web, App, HttpServer}; + + HttpServer::new(|| App::new().route("/", web::get().to(index))) + .bind("127.0.0.1:8088") + .unwrap() + .run() + .unwrap(); } // diff --git a/examples/errors/src/helpers.rs b/examples/errors/src/helpers.rs index 17da403..6dc01fd 100644 --- a/examples/errors/src/helpers.rs +++ b/examples/errors/src/helpers.rs @@ -1,13 +1,13 @@ use actix_web::{web, App}; // -use actix_web::{error, HttpRequest, Result}; +use actix_web::{error, Result}; #[derive(Debug)] struct MyError { name: &'static str, } -pub fn index(_req: HttpRequest) -> Result<&'static str> { +pub fn index() -> Result<&'static str> { let result: Result<&'static str, MyError> = Err(MyError { name: "test error" }); Ok(result.map_err(|e| error::ErrorBadRequest(e.name))?) diff --git a/examples/errors/src/main.rs b/examples/errors/src/main.rs index 97c55c3..5c5a69a 100644 --- a/examples/errors/src/main.rs +++ b/examples/errors/src/main.rs @@ -16,7 +16,7 @@ pub struct MyError { // Use default implementation for `error_response()` method impl error::ResponseError for MyError {} -fn index(_req: HttpRequest) -> Result<&'static str, MyError> { +fn index() -> Result<&'static str, MyError> { Err(MyError { name: "test" }) } // diff --git a/examples/errors/src/override_error.rs b/examples/errors/src/override_error.rs index 10da432..0f354cd 100644 --- a/examples/errors/src/override_error.rs +++ b/examples/errors/src/override_error.rs @@ -1,6 +1,6 @@ use actix_web::{web, App}; // -use actix_web::{error, http, HttpRequest, HttpResponse}; +use actix_web::{error, http, HttpResponse}; use failure::Fail; #[derive(Fail, Debug)] @@ -25,16 +25,16 @@ impl error::ResponseError for MyError { } } -fn index(_req: HttpRequest) -> Result<&'static str, MyError> { +fn index() -> Result<&'static str, MyError> { Err(MyError::BadClientData) } // -fn error2(_req: HttpRequest) -> Result<&'static str, MyError> { +fn error2() -> Result<&'static str, MyError> { Err(MyError::InternalError) } -fn error3(_req: HttpRequest) -> Result<&'static str, MyError> { +fn error3() -> Result<&'static str, MyError> { Err(MyError::Timeout) } diff --git a/examples/extractors/src/form.rs b/examples/extractors/src/form.rs index 394a255..daf58cf 100644 --- a/examples/extractors/src/form.rs +++ b/examples/extractors/src/form.rs @@ -1,5 +1,5 @@ //
-use actix_web::{web, App, HttpServer, Result}; +use actix_web::{web, Result}; use serde::Deserialize; #[derive(Deserialize)] @@ -16,6 +16,8 @@ fn index(form: web::Form) -> Result { // pub fn main() { + use actix_web::{App, HttpServer}; + HttpServer::new(|| App::new().route("/", web::post().to(index))) .bind("127.0.0.1:8088") .unwrap() diff --git a/examples/extractors/src/json_one.rs b/examples/extractors/src/json_one.rs index 255959d..d1600ce 100644 --- a/examples/extractors/src/json_one.rs +++ b/examples/extractors/src/json_one.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, HttpServer, Result}; +use actix_web::{web, Result}; use serde::Deserialize; #[derive(Deserialize)] @@ -14,6 +14,8 @@ fn index(info: web::Json) -> Result { // pub fn main() { + use actix_web::{App, HttpServer}; + HttpServer::new(|| App::new().route("/", web::post().to(index))) .bind("127.0.0.1:8088") .unwrap() diff --git a/examples/extractors/src/json_two.rs b/examples/extractors/src/json_two.rs index e5e8a22..a61a6cf 100644 --- a/examples/extractors/src/json_two.rs +++ b/examples/extractors/src/json_two.rs @@ -1,5 +1,5 @@ // -use actix_web::{error, web, App, FromRequest, HttpResponse, HttpServer, Responder}; +use actix_web::{error, web, FromRequest, HttpResponse, Responder}; use serde::Deserialize; #[derive(Deserialize)] @@ -13,6 +13,8 @@ fn index(info: web::Json) -> impl Responder { } pub fn main() { + use actix_web::{App, HttpServer}; + HttpServer::new(|| { App::new().service( web::resource("/") diff --git a/examples/extractors/src/multiple.rs b/examples/extractors/src/multiple.rs index 118dd5c..ed9cad1 100644 --- a/examples/extractors/src/multiple.rs +++ b/examples/extractors/src/multiple.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, HttpServer}; +use actix_web::web; use serde::Deserialize; #[derive(Deserialize)] @@ -15,6 +15,8 @@ fn index((path, query): (web::Path<(u32, String)>, web::Query)) -> String } pub fn main() { + use actix_web::{App, HttpServer}; + HttpServer::new(|| { App::new().route( "/users/{userid}/{friend}", // <- define path parameters diff --git a/examples/extractors/src/path_one.rs b/examples/extractors/src/path_one.rs index 0b83de8..1440b8e 100644 --- a/examples/extractors/src/path_one.rs +++ b/examples/extractors/src/path_one.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, HttpServer, Result}; +use actix_web::{web, Result}; /// extract path info from "/users/{userid}/{friend}" url /// {userid} - - deserializes to a u32 @@ -9,6 +9,8 @@ fn index(info: web::Path<(u32, String)>) -> Result { } pub fn main() { + use actix_web::{App, HttpServer}; + HttpServer::new(|| { App::new().route( "/users/{userid}/{friend}", // <- define path parameters diff --git a/examples/extractors/src/path_three.rs b/examples/extractors/src/path_three.rs index 9ca71c9..68badaa 100644 --- a/examples/extractors/src/path_three.rs +++ b/examples/extractors/src/path_three.rs @@ -1,4 +1,4 @@ -use actix_web::{web, App, HttpRequest, HttpServer, Result}; +use actix_web::{web, HttpRequest, Result}; // fn index(req: HttpRequest) -> Result { @@ -9,6 +9,8 @@ fn index(req: HttpRequest) -> Result { } pub fn main() { + use actix_web::{App, HttpServer}; + HttpServer::new(|| { App::new().route( "/users/{userid}/{friend}", // <- define path parameters diff --git a/examples/extractors/src/path_two.rs b/examples/extractors/src/path_two.rs index aa836d6..ee5e357 100644 --- a/examples/extractors/src/path_two.rs +++ b/examples/extractors/src/path_two.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, HttpServer, Result}; +use actix_web::{web, Result}; use serde::Deserialize; #[derive(Deserialize)] @@ -14,6 +14,8 @@ fn index(info: web::Path) -> Result { } pub fn main() { + use actix_web::{App, HttpServer}; + HttpServer::new(|| { App::new().route( "/users/{userid}/{friend}", // <- define path parameters diff --git a/examples/extractors/src/query.rs b/examples/extractors/src/query.rs index 10af0ce..74575ab 100644 --- a/examples/extractors/src/query.rs +++ b/examples/extractors/src/query.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, HttpServer}; +use actix_web::web; use serde::Deserialize; #[derive(Deserialize)] @@ -14,6 +14,8 @@ fn index(info: web::Query) -> String { // pub fn main() { + use actix_web::{App, HttpServer}; + HttpServer::new(|| App::new().route("/", web::get().to(index))) .bind("127.0.0.1:8088") .unwrap() diff --git a/examples/getting-started/src/main.rs b/examples/getting-started/src/main.rs index 821e428..4b2cfa6 100644 --- a/examples/getting-started/src/main.rs +++ b/examples/getting-started/src/main.rs @@ -1,11 +1,11 @@ // -use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder}; +use actix_web::{web, App, HttpResponse, HttpServer, Responder}; fn index() -> impl Responder { HttpResponse::Ok().body("Hello world!") } -fn index2(_req: HttpRequest) -> impl Responder { +fn index2() -> impl Responder { HttpResponse::Ok().body("Hello world again!") } // diff --git a/examples/request-handlers/src/handlers_arc.rs b/examples/request-handlers/src/handlers_arc.rs index f3002d8..cd9acbe 100644 --- a/examples/request-handlers/src/handlers_arc.rs +++ b/examples/request-handlers/src/handlers_arc.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, HttpServer, Responder}; +use actix_web::{web, Responder}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; @@ -19,6 +19,8 @@ fn add_one(data: web::Data) -> impl Responder { } pub fn main() { + use actix_web::{App, HttpServer}; + let data = AppState { count: Arc::new(AtomicUsize::new(0)), }; diff --git a/examples/request-handlers/src/main.rs b/examples/request-handlers/src/main.rs index 48d7842..9fb1734 100644 --- a/examples/request-handlers/src/main.rs +++ b/examples/request-handlers/src/main.rs @@ -1,6 +1,6 @@ pub mod handlers_arc; // -use actix_web::{web, App, HttpServer, Responder}; +use actix_web::{web, Responder}; use std::cell::Cell; #[derive(Clone)] @@ -20,6 +20,8 @@ fn add_one(data: web::Data) -> impl Responder { } fn main() { + use actix_web::{App, HttpServer}; + let data = AppState { count: Cell::new(0), }; diff --git a/examples/responder-trait/src/main.rs b/examples/responder-trait/src/main.rs index 869ea54..5b199b3 100644 --- a/examples/responder-trait/src/main.rs +++ b/examples/responder-trait/src/main.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder}; +use actix_web::{Error, HttpRequest, HttpResponse, Responder}; use serde::Serialize; #[derive(Serialize)] @@ -28,6 +28,8 @@ fn index() -> impl Responder { // fn main() { + use actix_web::{web, App, HttpServer}; + HttpServer::new(|| App::new().route("/", web::get().to(index))) .bind("127.0.0.1:8088") .unwrap() diff --git a/examples/responses/src/chunked.rs b/examples/responses/src/chunked.rs index 50899cb..0c80ed4 100644 --- a/examples/responses/src/chunked.rs +++ b/examples/responses/src/chunked.rs @@ -1,4 +1,4 @@ -// +// // // use actix_web::{web, HttpRequest, HttpResponse}; // use bytes::Bytes; // use futures::stream::once; @@ -10,7 +10,7 @@ // b"data", // )))))) // } -// +// // // pub fn main() { // use actix_web::{web, App, HttpServer}; diff --git a/examples/responses/src/identity_two.rs b/examples/responses/src/identity_two.rs index 494e9d9..62839ff 100644 --- a/examples/responses/src/identity_two.rs +++ b/examples/responses/src/identity_two.rs @@ -1,7 +1,6 @@ // use actix_web::{ - http::ContentEncoding, middleware, middleware::BodyEncoding, HttpRequest, - HttpResponse, + http::ContentEncoding, middleware, middleware::BodyEncoding, HttpResponse, }; static HELLO_WORLD: &[u8] = &[ @@ -10,7 +9,7 @@ static HELLO_WORLD: &[u8] = &[ 0x0c, 0x00, 0x00, 0x00, ]; -pub fn index(_req: HttpRequest) -> HttpResponse { +pub fn index() -> HttpResponse { HttpResponse::Ok() .encoding(ContentEncoding::Identity) .header("content-encoding", "gzip") diff --git a/examples/responses/src/main.rs b/examples/responses/src/main.rs index 61e4679..d41f2b7 100644 --- a/examples/responses/src/main.rs +++ b/examples/responses/src/main.rs @@ -7,11 +7,10 @@ pub mod identity_two; pub mod json_resp; // -use actix_web::{http::ContentEncoding, middleware::BodyEncoding, HttpResponse}; +use actix_web::HttpResponse; fn index() -> HttpResponse { HttpResponse::Ok() - .encoding(ContentEncoding::Br) .content_type("plain/text") .header("X-Hdr", "sample") .body("data") diff --git a/examples/static-files/src/main.rs b/examples/static-files/src/main.rs index 1e06d23..a30d5db 100644 --- a/examples/static-files/src/main.rs +++ b/examples/static-files/src/main.rs @@ -4,7 +4,7 @@ pub mod directory; // use actix_files::NamedFile; -use actix_web::{web, App, HttpRequest, HttpServer, Result}; +use actix_web::{HttpRequest, Result}; use std::path::PathBuf; fn index(req: HttpRequest) -> Result { @@ -13,6 +13,8 @@ fn index(req: HttpRequest) -> Result { } fn main() { + use actix_web::{web, App, HttpServer}; + HttpServer::new(|| App::new().route("/{filename:.*}", web::get().to(index))) .bind("127.0.0.1:8088") .unwrap() diff --git a/examples/url-dispatch/src/guard.rs b/examples/url-dispatch/src/guard.rs index 19bd514..1ef5d6b 100644 --- a/examples/url-dispatch/src/guard.rs +++ b/examples/url-dispatch/src/guard.rs @@ -1,7 +1,5 @@ // -use actix_web::{ - dev::RequestHead, guard::Guard, http, web, App, HttpResponse, HttpServer, -}; +use actix_web::{dev::RequestHead, guard::Guard, http, HttpResponse}; struct ContentTypeHeader; @@ -12,6 +10,8 @@ impl Guard for ContentTypeHeader { } pub fn main() { + use actix_web::{web, App, HttpServer}; + HttpServer::new(|| { App::new().route( "/", diff --git a/examples/url-dispatch/src/minfo.rs b/examples/url-dispatch/src/minfo.rs index 920611a..7c993d7 100644 --- a/examples/url-dispatch/src/minfo.rs +++ b/examples/url-dispatch/src/minfo.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, HttpRequest, Result}; +use actix_web::{HttpRequest, HttpResponse, Result}; fn index(req: HttpRequest) -> Result { let v1: u8 = req.match_info().get("v1").unwrap().parse().unwrap(); @@ -9,12 +9,12 @@ fn index(req: HttpRequest) -> Result { } pub fn main() { - use actix_web::HttpServer; + use actix_web::{web, App, HttpServer}; HttpServer::new(|| { App::new() .route("/a/{v1}/{v2}/", web::get().to(index)) - .route("", web::get().to(|| actix_web::HttpResponse::Ok())) + .route("", web::get().to(|| HttpResponse::Ok())) }) .bind("127.0.0.1:8088") .unwrap() diff --git a/examples/url-dispatch/src/norm.rs b/examples/url-dispatch/src/norm.rs index 75723d0..4d1abf7 100644 --- a/examples/url-dispatch/src/norm.rs +++ b/examples/url-dispatch/src/norm.rs @@ -1,12 +1,12 @@ // -use actix_web::{middleware, web, App, HttpResponse}; +use actix_web::{middleware, HttpResponse}; fn index() -> HttpResponse { HttpResponse::Ok().body("Hello") } pub fn main() { - use actix_web::HttpServer; + use actix_web::{web, App, HttpServer}; HttpServer::new(|| { App::new() diff --git a/examples/url-dispatch/src/norm2.rs b/examples/url-dispatch/src/norm2.rs index bd0f019..a704fa7 100644 --- a/examples/url-dispatch/src/norm2.rs +++ b/examples/url-dispatch/src/norm2.rs @@ -1,3 +1,9 @@ +use actix_web::HttpResponse; + +fn index() -> HttpResponse { + HttpResponse::Ok().body("Hello") +} + // use actix_web::{http::Method, middleware, web, App, HttpServer}; @@ -14,9 +20,3 @@ pub fn main() { .unwrap(); } // - -use actix_web::HttpResponse; - -fn index() -> HttpResponse { - HttpResponse::Ok().body("Hello") -} diff --git a/examples/url-dispatch/src/path.rs b/examples/url-dispatch/src/path.rs index 1c84400..11e2a99 100644 --- a/examples/url-dispatch/src/path.rs +++ b/examples/url-dispatch/src/path.rs @@ -1,12 +1,12 @@ // -use actix_web::{web, App, Result}; +use actix_web::{web, Result}; fn index(info: web::Path<(String, u32)>) -> Result { Ok(format!("Welcome {}! id: {}", info.0, info.1)) } pub fn main() { - use actix_web::HttpServer; + use actix_web::{App, HttpServer}; HttpServer::new(|| { App::new().route( diff --git a/examples/url-dispatch/src/path2.rs b/examples/url-dispatch/src/path2.rs index 783949f..799a412 100644 --- a/examples/url-dispatch/src/path2.rs +++ b/examples/url-dispatch/src/path2.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, Result}; +use actix_web::{web, Result}; use serde::Deserialize; #[derive(Deserialize)] @@ -13,7 +13,7 @@ fn index(info: web::Path) -> Result { } pub fn main() { - use actix_web::HttpServer; + use actix_web::{App, HttpServer}; HttpServer::new(|| { App::new().route( diff --git a/examples/url-dispatch/src/pbuf.rs b/examples/url-dispatch/src/pbuf.rs index 1319ad0..36b7e7c 100644 --- a/examples/url-dispatch/src/pbuf.rs +++ b/examples/url-dispatch/src/pbuf.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, HttpRequest, Result}; +use actix_web::{HttpRequest, Result}; use std::path::PathBuf; fn index(req: HttpRequest) -> Result { @@ -8,7 +8,7 @@ fn index(req: HttpRequest) -> Result { } pub fn main() { - use actix_web::HttpServer; + use actix_web::{web, App, HttpServer}; HttpServer::new(|| App::new().route(r"/a/{tail:.*}", web::get().to(index))) .bind("127.0.0.1:8088") diff --git a/examples/url-dispatch/src/scope.rs b/examples/url-dispatch/src/scope.rs index 388acef..11ac91e 100644 --- a/examples/url-dispatch/src/scope.rs +++ b/examples/url-dispatch/src/scope.rs @@ -5,8 +5,8 @@ fn show_users() -> HttpResponse { HttpResponse::Ok().body("Show users") } -fn user_detail(_path: web::Path<(u32,)>) -> HttpResponse { - HttpResponse::Ok().body("User detail") +fn user_detail(path: web::Path<(u32,)>) -> HttpResponse { + HttpResponse::Ok().body(format!("User detail: {}", path.0)) } pub fn main() { diff --git a/examples/url-dispatch/src/url_ext.rs b/examples/url-dispatch/src/url_ext.rs index fafb66d..7de8e6e 100644 --- a/examples/url-dispatch/src/url_ext.rs +++ b/examples/url-dispatch/src/url_ext.rs @@ -1,5 +1,5 @@ // -use actix_web::{web, App, HttpRequest, Responder}; +use actix_web::{HttpRequest, Responder}; fn index(req: HttpRequest) -> impl Responder { let url = req.url_for("youtube", &["oHg5SJYRHA0"]).unwrap(); @@ -9,7 +9,7 @@ fn index(req: HttpRequest) -> impl Responder { } pub fn main() { - use actix_web::HttpServer; + use actix_web::{web, App, HttpServer}; HttpServer::new(|| { App::new() diff --git a/examples/url-dispatch/src/urls.rs b/examples/url-dispatch/src/urls.rs index 24cff65..8fc03fb 100644 --- a/examples/url-dispatch/src/urls.rs +++ b/examples/url-dispatch/src/urls.rs @@ -1,5 +1,5 @@ // -use actix_web::{guard, http::header, web, App, HttpRequest, HttpResponse, Result}; +use actix_web::{guard, http::header, HttpRequest, HttpResponse, Result}; fn index(req: HttpRequest) -> Result { let url = req.url_for("foo", &["1", "2", "3"])?; // <- generate url for "foo" resource @@ -10,7 +10,7 @@ fn index(req: HttpRequest) -> Result { } pub fn main() { - use actix_web::HttpServer; + use actix_web::{web, App, HttpServer}; HttpServer::new(|| { App::new() diff --git a/layouts/index.html b/layouts/index.html index 53c147c..d0e1648 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -70,7 +70,6 @@ fn main() { to return consistent responses from your APIs.

{{ highlight `#[derive(Serialize)] -#[derive(Serialize)] struct Measurement { temperature: f32, }