diff --git a/content/docs/application.md b/content/docs/application.md
index 177c615..68f2aad 100644
--- a/content/docs/application.md
+++ b/content/docs/application.md
@@ -23,7 +23,7 @@ The prefix should consist of value path segments.
> any request with the paths `/app`, `/app/`, or `/app/test` would match;
> however, the path `/application` would not match.
-{{< include-example example="application" section="make_app" >}}
+{{< include-example example="application" file="app.rs" section="setup" >}}
In this example, an application with the `/app` prefix and a `index.html` resource
are created. This resource is available through the `/app/index.html` url.
@@ -33,7 +33,7 @@ are created. This resource is available through the `/app/index.html` url.
Multiple applications can be served with one server:
-{{< include-example example="application" section="run_server" >}}
+{{< include-example example="application" file="main.rs" section="run_server" >}}
All `/app1` requests route to the first application, `/app2` to the second, and all other to the third.
**Applications get matched based on registration order**. If an application with a more generic
@@ -61,8 +61,7 @@ When the app is initialized it needs to be passed the initial state:
> instance. Http server constructs an application instance for each thread, thus application state
> must be constructed multiple times. If you want to share state between different threads, a
> shared object should be used, e.g. `Arc`. There is also an [Example](https://github.com/actix/examples/blob/master/state/src/main.rs) using `Arc` for this. Application state does not need to be `Send` and `Sync`,
-> but the application factory must be `Send` + `Sync`.
->
+> but the application factory must be `Send` + `Sync`.
To start the previous app, create it into a closure:
@@ -76,7 +75,7 @@ Combining multiple applications with different state is possible as well.
This limitation can easily be overcome with the [App::boxed](https://docs.rs/actix-web/*/actix_web/struct.App.html#method.boxed) method, which converts an App into a boxed trait object.
-{{< include-example example="application" file="state.rs" section="combine" >}}
+{{< include-example example="application" file="combine.rs" section="combine" >}}
## Using an Application Scope to Compose Applications
diff --git a/examples/Cargo.toml b/examples/Cargo.toml
index 52454ac..b5dc000 100644
--- a/examples/Cargo.toml
+++ b/examples/Cargo.toml
@@ -11,20 +11,20 @@ members = [
"url-dispatch",
"responder-trait",
"either",
-]
-exclude = [
- "request-handlers",
- "async-handlers",
"extractors",
"autoreload",
"errors",
"requests",
"responses",
- "testing",
"middleware",
"static-files",
- "websockets",
"http2",
+]
+exclude = [
+ "testing",
+ "async-handlers",
+ "websockets",
+ "request-handlers",
"og_databases",
"sentry",
]
diff --git a/examples/application/src/app.rs b/examples/application/src/app.rs
new file mode 100644
index 0000000..375c2a3
--- /dev/null
+++ b/examples/application/src/app.rs
@@ -0,0 +1,11 @@
+//
+use actix_web::{web, App, HttpRequest, Responder};
+
+fn index(_req: HttpRequest) -> impl Responder {
+ "Hello world!"
+}
+
+pub fn main() {
+ App::new().service(web::scope("/app").route("/index.html", web::get().to(index)));
+}
+//
diff --git a/examples/application/src/combine.rs b/examples/application/src/combine.rs
new file mode 100644
index 0000000..1057f68
--- /dev/null
+++ b/examples/application/src/combine.rs
@@ -0,0 +1,25 @@
+use actix_web::{web, App, HttpResponse, HttpServer};
+
+//
+struct State1;
+struct State2;
+
+#[rustfmt::skip]
+pub fn main() {
+ HttpServer::new(|| {
+ App::new()
+ .data(State1)
+ .data(State2)
+ .service(
+ web::scope("/app1")
+ .route("/", web::to(|| HttpResponse::Ok())))
+ .service(
+ web::scope("/app2")
+ .route("/", web::to(|| HttpResponse::Ok())))
+ })
+ .bind("127.0.0.1:8088")
+ .unwrap()
+ .run()
+ .unwrap();
+}
+//
diff --git a/examples/application/src/main.rs b/examples/application/src/main.rs
index 172c57e..be51f1d 100644
--- a/examples/application/src/main.rs
+++ b/examples/application/src/main.rs
@@ -1,37 +1,22 @@
-#![allow(unused_variables)]
-use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
+use actix_web::{web, App, HttpResponse, HttpServer};
-mod state;
-mod vh;
+pub mod app;
+pub mod combine;
+pub mod state;
+pub mod vh;
#[rustfmt::skip]
-fn make_app() {
-
-//
-fn index(_req: HttpRequest) -> impl Responder {
- "Hello world!"
-}
-
-let app = App::new()
- .service(web::scope("/app").route("/index.html", web::get().to(index)));
-//
-
-}
-
-#[rustfmt::skip]
-fn run_server() {
//
-let server = HttpServer::new(|| {
- App::new()
- .service(web::scope("/app1").route("/", web::to(|| HttpResponse::Ok())))
- .service(web::scope("/app2").route("/", web::to(|| HttpResponse::Ok())))
- .route("/", web::to(|| HttpResponse::Ok()))
-});
-//
-}
-
fn main() {
- make_app();
- run_server();
- state::test();
+ HttpServer::new(|| {
+ App::new()
+ .service(
+ web::scope("/app1")
+ .route("/", web::to(|| HttpResponse::Ok())))
+ .service(
+ web::scope("/app2")
+ .route("/", web::to(|| HttpResponse::Ok())))
+ .route("/", web::to(|| HttpResponse::Ok()))
+ });
}
+//
diff --git a/examples/application/src/state.rs b/examples/application/src/state.rs
index 19fd96d..9944412 100644
--- a/examples/application/src/state.rs
+++ b/examples/application/src/state.rs
@@ -1,6 +1,5 @@
-#![allow(dead_code, unused)]
//
-use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
+use actix_web::{web, App, HttpServer};
use std::cell::Cell;
// This struct represents state
@@ -16,63 +15,28 @@ fn index(data: web::Data) -> String {
}
//
-#[rustfmt::skip]
-fn make_app() {
//
-App::new()
- .data( AppState { counter: Cell::new(0) })
- .route("/", web::get().to(index));
-//
-}
-
-#[rustfmt::skip]
-fn start_app() {
-//
-HttpServer::new(|| {
+fn _main() {
App::new()
- .data( AppState { counter: Cell::new(0) })
- .route("/", web::get().to(index))
-})
-.bind("127.0.0.1:8088")
-.unwrap()
-.run()
-.unwrap();
-//
+ .data(AppState {
+ counter: Cell::new(0),
+ })
+ .route("/", web::get().to(index));
}
+//
-use std::thread;
-
-#[rustfmt::skip]
-fn combine() {
- thread::spawn(|| {
-//
-struct State1;
-struct State2;
-
-fn main() {
+//
+pub fn main() {
HttpServer::new(|| {
App::new()
- .data(State1)
- .data(State2)
- .service(
- web::scope("/app1")
- .route("/", web::to(|| HttpResponse::Ok())),
- )
- .service(
- web::scope("/app2")
- .route("/", web::to(|| HttpResponse::Ok())),
- )
+ .data(AppState {
+ counter: Cell::new(0),
+ })
+ .route("/", web::get().to(index))
})
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
}
-//
- });
-}
-
-pub fn test() {
- make_app();
- combine();
-}
+//
diff --git a/examples/errors/src/helpers.rs b/examples/errors/src/helpers.rs
index 9fcd86a..bbdb0be 100644
--- a/examples/errors/src/helpers.rs
+++ b/examples/errors/src/helpers.rs
@@ -1,3 +1,4 @@
+use actix_web::{web, App};
//
use actix_web::{error, HttpRequest, Result};
@@ -6,9 +7,12 @@ struct MyError {
name: &'static str,
}
-fn index(req: &HttpRequest) -> Result<&'static str> {
+pub fn index(_req: HttpRequest) -> Result<&'static str> {
let result: Result<&'static str, MyError> = Err(MyError { name: "test" });
Ok(result.map_err(|e| error::ErrorBadRequest(e.name))?)
}
//
+pub fn main() {
+ App::new().route("/", web::get().to(index));
+}
diff --git a/examples/errors/src/main.rs b/examples/errors/src/main.rs
index 63e09b9..637cda4 100644
--- a/examples/errors/src/main.rs
+++ b/examples/errors/src/main.rs
@@ -1,21 +1,24 @@
-mod helpers;
-mod override_error;
-mod recommend_one;
+pub mod helpers;
+pub mod override_error;
+pub mod recommend_one;
+use actix_web::{web, App};
//
use actix_web::{error, HttpRequest};
use failure::Fail;
#[derive(Fail, Debug)]
#[fail(display = "my error")]
-struct MyError {
+pub struct MyError {
name: &'static str,
}
// Use default implementation for `error_response()` method
impl error::ResponseError for MyError {}
-fn index(req: HttpRequest) -> Result<&'static str, MyError> {
+fn index(_req: HttpRequest) -> Result<&'static str, MyError> {
Err(MyError { name: "test" })
}
//
-fn main() {}
+pub fn main() {
+ App::new().route("/", web::get().to(index));
+}
diff --git a/examples/errors/src/override_error.rs b/examples/errors/src/override_error.rs
index a5eaea3..98870ac 100644
--- a/examples/errors/src/override_error.rs
+++ b/examples/errors/src/override_error.rs
@@ -1,3 +1,4 @@
+use actix_web::{web, App};
//
use actix_web::{error, http, HttpRequest, HttpResponse};
use failure::Fail;
@@ -24,7 +25,21 @@ impl error::ResponseError for MyError {
}
}
-fn index(req: &HttpRequest) -> Result<&'static str, MyError> {
+fn index(_req: HttpRequest) -> Result<&'static str, MyError> {
Err(MyError::BadClientData)
}
//
+pub fn main() {
+ App::new()
+ .route("/", web::get().to(index))
+ .route("/e2", web::get().to(error2))
+ .route("/e3", web::get().to(error3));
+}
+
+fn error2(_req: HttpRequest) -> Result<&'static str, MyError> {
+ Err(MyError::InternalError)
+}
+
+fn error3(_req: HttpRequest) -> Result<&'static str, MyError> {
+ Err(MyError::Timeout)
+}
diff --git a/examples/errors/src/recommend_one.rs b/examples/errors/src/recommend_one.rs
index 51b6131..c88048e 100644
--- a/examples/errors/src/recommend_one.rs
+++ b/examples/errors/src/recommend_one.rs
@@ -1,3 +1,4 @@
+use actix_web::{web, App, HttpRequest};
//
use actix_web::{error, http, HttpResponse};
use failure::Fail;
@@ -18,3 +19,12 @@ impl error::ResponseError for UserError {
}
}
//
+pub fn main() {
+ App::new().route("/", web::get().to(index));
+}
+
+fn index(_req: HttpRequest) -> Result<&'static str, UserError> {
+ Err(UserError::ValidationError {
+ field: "bad stuff".to_string(),
+ })
+}
diff --git a/examples/errors/src/recommend_two.rs b/examples/errors/src/recommend_two.rs
index 80e5f1f..e587d32 100644
--- a/examples/errors/src/recommend_two.rs
+++ b/examples/errors/src/recommend_two.rs
@@ -1,5 +1,6 @@
+use actix_web::App;
//
-use actix_web::{error, fs, http, App, HttpRequest, HttpResponse};
+use actix_web::{error, fs, http, HttpRequest, HttpResponse};
use failure::Fail;
#[derive(Fail, Debug)]
@@ -23,3 +24,6 @@ fn index(_req: HttpRequest) -> Result<&'static str, UserError> {
Ok("success!")
}
//
+pub fn main() {
+ App::new().route("/", web::get().to(index));
+}
diff --git a/examples/extractors/src/main.rs b/examples/extractors/src/main.rs
index 917f532..276b1b6 100644
--- a/examples/extractors/src/main.rs
+++ b/examples/extractors/src/main.rs
@@ -2,14 +2,14 @@ use actix_web::{web, App, FromRequest, HttpRequest, HttpServer, Responder};
use futures::future::Future;
use serde::Deserialize;
-// mod custom_handler;
-mod form;
-mod json_one;
-mod json_two;
-mod multiple;
-mod path_one;
-mod path_two;
-mod query;
+// pub mod custom_handler;
+pub mod form;
+pub mod json_one;
+pub mod json_two;
+pub mod multiple;
+pub mod path_one;
+pub mod path_two;
+pub mod query;
#[derive(Deserialize, Debug)]
struct MyInfo {
diff --git a/examples/extractors/src/path_two.rs b/examples/extractors/src/path_two.rs
index 7919173..7c5a4c3 100644
--- a/examples/extractors/src/path_two.rs
+++ b/examples/extractors/src/path_two.rs
@@ -10,7 +10,7 @@ struct Info {
/// extract path info using serde
fn index(info: web::Path) -> Result {
- Ok(format!("Welcome {}!", info.friend))
+ Ok(format!("Welcome {}, userid {}!", info.friend, info.userid))
}
pub fn main() {
diff --git a/examples/middleware/src/default_headers.rs b/examples/middleware/src/default_headers.rs
index a81e7a1..cf14468 100644
--- a/examples/middleware/src/default_headers.rs
+++ b/examples/middleware/src/default_headers.rs
@@ -1,7 +1,7 @@
//
use actix_web::{http, middleware, web, App, HttpResponse};
-fn main() {
+pub fn main() {
App::new()
.wrap(middleware::DefaultHeaders::new().header("X-Version", "0.2"))
.service(
diff --git a/examples/middleware/src/errorhandler.rs b/examples/middleware/src/errorhandler.rs
index dd3b440..6d33db5 100644
--- a/examples/middleware/src/errorhandler.rs
+++ b/examples/middleware/src/errorhandler.rs
@@ -10,7 +10,7 @@ fn render_500(mut res: dev::ServiceResponse) -> Result
use actix_service::{Service, Transform};
use actix_web::{dev::ServiceRequest, dev::ServiceResponse, web, App, Error};
diff --git a/examples/middleware/src/user_sessions.rs b/examples/middleware/src/user_sessions.rs
index 42fafff..d51c740 100644
--- a/examples/middleware/src/user_sessions.rs
+++ b/examples/middleware/src/user_sessions.rs
@@ -19,7 +19,7 @@ fn index(session: Session, req: HttpRequest) -> Result<&'static str> {
Ok("welcome!")
}
-fn main() -> std::io::Result<()> {
+pub fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
diff --git a/examples/requests/src/json_two.rs b/examples/requests/src/json_two.rs
index 659bd96..5c0bfa8 100644
--- a/examples/requests/src/json_two.rs
+++ b/examples/requests/src/json_two.rs
@@ -9,7 +9,7 @@
// number: i32,
// }
-// fn index(req: HttpRequest) -> Box> {
+// pub fn index(req: HttpRequest) -> Box> {
// req.json()
// .from_err()
// .and_then(|val: MyObj| {
diff --git a/examples/requests/src/main.rs b/examples/requests/src/main.rs
index 9b3ad62..b44e0bd 100644
--- a/examples/requests/src/main.rs
+++ b/examples/requests/src/main.rs
@@ -1,8 +1,8 @@
-mod json_two;
-mod manual;
-mod multipart;
-mod streaming;
-mod urlencoded;
+pub mod json_two;
+pub mod manual;
+pub mod multipart;
+pub mod streaming;
+pub mod urlencoded;
//
use actix_web::{web, App, Result};
use serde::Deserialize;
diff --git a/examples/requests/src/manual.rs b/examples/requests/src/manual.rs
index 846f704..a850b0e 100644
--- a/examples/requests/src/manual.rs
+++ b/examples/requests/src/manual.rs
@@ -1,5 +1,5 @@
//
-use actix_web::{error, web, Error, HttpResponse};
+use actix_web::{error, web, App, Error, HttpResponse};
use bytes::BytesMut;
use futures::{Future, Stream};
use serde::{Deserialize, Serialize};
@@ -13,7 +13,7 @@ struct MyObj {
const MAX_SIZE: usize = 262_144; // max payload size is 256k
-fn index_manual(
+pub fn index_manual(
payload: web::Payload,
) -> impl Future- {
// payload is a stream of Bytes objects
@@ -41,3 +41,7 @@ fn index_manual(
})
}
//
+
+pub fn main() {
+ App::new().route("/", web::post().to_async(index_manual));
+}
diff --git a/examples/requests/src/multipart.rs b/examples/requests/src/multipart.rs
index 0fa74d9..94199a1 100644
--- a/examples/requests/src/multipart.rs
+++ b/examples/requests/src/multipart.rs
@@ -2,7 +2,7 @@
// use actix_web::{error, Error, HttpRequest, HttpResponse};
// use futures::Future;
-// fn index(req: HttpRequest) -> Box> {
+// pub fn index(req: HttpRequest) -> Box> {
// // get multipart and iterate over multipart items
// req.multipart().and_then(|item| match item {
// multipart::MultipartItem::Field(field) => {
diff --git a/examples/requests/src/streaming.rs b/examples/requests/src/streaming.rs
index 191d32a..6444171 100644
--- a/examples/requests/src/streaming.rs
+++ b/examples/requests/src/streaming.rs
@@ -2,7 +2,7 @@
// use actix_web::{error, web, Error, HttpResponse};
// use futures::{future::result, Future, Stream};
-// fn index(payload: web::Payload) -> Box> {
+// pub fn index(payload: web::Payload) -> Box> {
// payload
// .from_err()
// .fold((), |_, chunk| {
diff --git a/examples/requests/src/urlencoded.rs b/examples/requests/src/urlencoded.rs
index 5439d0d..5e64efb 100644
--- a/examples/requests/src/urlencoded.rs
+++ b/examples/requests/src/urlencoded.rs
@@ -19,4 +19,4 @@
// .responder()
// }
//
-fn main() {}
+pub fn main() {}
diff --git a/examples/responses/src/auto.rs b/examples/responses/src/auto.rs
index 598513a..d4b2cb7 100644
--- a/examples/responses/src/auto.rs
+++ b/examples/responses/src/auto.rs
@@ -3,12 +3,12 @@ use actix_web::{
http::ContentEncoding, middleware, web, App, HttpRequest, HttpResponse,
};
-fn index(req: HttpRequest) -> HttpResponse {
+fn index(_req: HttpRequest) -> HttpResponse {
HttpResponse::Ok().body("data")
}
-fn main() {
- let app = App::new()
+pub fn main() {
+ App::new()
// v- disable compression for all routes
.wrap(middleware::Compress::new(ContentEncoding::Identity))
.route("/", web::get().to(index));
diff --git a/examples/responses/src/brotli.rs b/examples/responses/src/brotli.rs
index e107ad7..79717ff 100644
--- a/examples/responses/src/brotli.rs
+++ b/examples/responses/src/brotli.rs
@@ -3,11 +3,14 @@ use actix_web::{
http::ContentEncoding, middleware::BodyEncoding, HttpRequest, HttpResponse,
};
-fn index_br(req: HttpRequest) -> HttpResponse {
+fn index_br(_req: HttpRequest) -> HttpResponse {
HttpResponse::Ok()
.encoding(ContentEncoding::Br)
.body("data")
}
//
-fn main() {}
+use actix_web::{web, App};
+pub fn main() {
+ App::new().route("/", web::get().to(index_br));
+}
diff --git a/examples/responses/src/chunked.rs b/examples/responses/src/chunked.rs
index 0cd6d76..a2c4a62 100644
--- a/examples/responses/src/chunked.rs
+++ b/examples/responses/src/chunked.rs
@@ -11,4 +11,4 @@
// ))))))
// }
//
-fn main() {}
+pub fn main() {}
diff --git a/examples/responses/src/identity.rs b/examples/responses/src/identity.rs
index 89bd52e..039d713 100644
--- a/examples/responses/src/identity.rs
+++ b/examples/responses/src/identity.rs
@@ -3,10 +3,15 @@ use actix_web::{
http::ContentEncoding, middleware::BodyEncoding, HttpRequest, HttpResponse,
};
-fn index(req: HttpRequest) -> HttpResponse {
+fn index(_req: HttpRequest) -> HttpResponse {
HttpResponse::Ok()
// v- disable compression
.encoding(ContentEncoding::Identity)
.body("data")
}
//
+
+use actix_web::{web, App};
+pub fn main() {
+ App::new().route("/", web::get().to(index));
+}
diff --git a/examples/responses/src/identity_two.rs b/examples/responses/src/identity_two.rs
index 63371fa..0ac8f65 100644
--- a/examples/responses/src/identity_two.rs
+++ b/examples/responses/src/identity_two.rs
@@ -16,3 +16,8 @@ pub fn index(_req: HttpRequest) -> HttpResponse {
.body(HELLO_WORLD)
}
//
+
+use actix_web::{web, App};
+pub fn main() {
+ App::new().route("/", web::get().to(index));
+}
diff --git a/examples/responses/src/json_resp.rs b/examples/responses/src/json_resp.rs
index c2344c0..96d9591 100644
--- a/examples/responses/src/json_resp.rs
+++ b/examples/responses/src/json_resp.rs
@@ -13,7 +13,7 @@ fn index(req: HttpRequest) -> Result> {
}))
}
-fn main() {
+pub fn main() {
App::new().route(r"/a/{name}", web::get().to(index));
}
//
diff --git a/examples/responses/src/main.rs b/examples/responses/src/main.rs
index 4c9f209..943612e 100644
--- a/examples/responses/src/main.rs
+++ b/examples/responses/src/main.rs
@@ -1,9 +1,9 @@
-mod auto;
-mod brotli;
-mod chunked;
-mod identity;
-mod identity_two;
-mod json_resp;
+pub mod auto;
+pub mod brotli;
+pub mod chunked;
+pub mod identity;
+pub mod identity_two;
+pub mod json_resp;
//
use actix_web::{
http::ContentEncoding, middleware::BodyEncoding, HttpRequest, HttpResponse,
@@ -18,4 +18,7 @@ fn index(_req: HttpRequest) -> HttpResponse {
}
//
-fn main() {}
+use actix_web::{web, App};
+pub fn main() {
+ App::new().route("/", web::get().to(index));
+}
diff --git a/examples/server/src/keep_alive.rs b/examples/server/src/keep_alive.rs
index b078961..86aa88f 100644
--- a/examples/server/src/keep_alive.rs
+++ b/examples/server/src/keep_alive.rs
@@ -1,7 +1,7 @@
//
use actix_web::{web, App, HttpResponse, HttpServer};
-fn main() {
+pub fn main() {
HttpServer::new(|| {
App::new().route("/", web::get().to(|| HttpResponse::Ok()))
})
diff --git a/examples/server/src/keep_alive_tp.rs b/examples/server/src/keep_alive_tp.rs
index aac81cc..252c53c 100644
--- a/examples/server/src/keep_alive_tp.rs
+++ b/examples/server/src/keep_alive_tp.rs
@@ -1,7 +1,7 @@
//
use actix_web::{http, HttpRequest, HttpResponse};
-fn index(req: HttpRequest) -> HttpResponse {
+pub fn index(req: HttpRequest) -> HttpResponse {
HttpResponse::Ok()
.connection_type(http::ConnectionType::Close) // <- Close connection
.force_close() // <- Alternative method
diff --git a/examples/server/src/main.rs b/examples/server/src/main.rs
index 95995d7..735f613 100644
--- a/examples/server/src/main.rs
+++ b/examples/server/src/main.rs
@@ -1,8 +1,8 @@
-// mod keep_alive;
-// mod keep_alive_tp;
-mod signals;
-mod ssl;
-mod workers;
+// pub mod keep_alive;
+// pub mod keep_alive_tp;
+pub mod signals;
+pub mod ssl;
+pub mod workers;
//
use actix_web::{web, App, HttpResponse, HttpServer};
diff --git a/examples/static-files/src/directory.rs b/examples/static-files/src/directory.rs
index b547650..3fcbbe4 100644
--- a/examples/static-files/src/directory.rs
+++ b/examples/static-files/src/directory.rs
@@ -2,7 +2,7 @@
use actix_files as fs;
use actix_web::App;
-fn main() {
+pub fn main() {
App::new().service(fs::Files::new("/static", ".").show_files_listing());
}
//
diff --git a/examples/static-files/src/main.rs b/examples/static-files/src/main.rs
index 4d1840a..907afff 100644
--- a/examples/static-files/src/main.rs
+++ b/examples/static-files/src/main.rs
@@ -1,6 +1,6 @@
-mod configuration;
-mod configuration_two;
-mod directory;
+pub mod configuration;
+pub mod configuration_two;
+pub mod directory;
//
use actix_files::NamedFile;
use actix_web::{web, App, HttpRequest, Result};
diff --git a/examples/url-dispatch/src/dhandler.rs b/examples/url-dispatch/src/dhandler.rs
index 46a9a75..cb7a3db 100644
--- a/examples/url-dispatch/src/dhandler.rs
+++ b/examples/url-dispatch/src/dhandler.rs
@@ -5,7 +5,7 @@ fn index(_req: HttpRequest) -> impl Responder {
}
//
-fn main() {
+pub fn main() {
App::new()
.service(web::resource("/").route(web::get().to(index)))
.default_service(
diff --git a/examples/url-dispatch/src/main.rs b/examples/url-dispatch/src/main.rs
index c2e4ae0..bea247a 100644
--- a/examples/url-dispatch/src/main.rs
+++ b/examples/url-dispatch/src/main.rs
@@ -1,17 +1,17 @@
-mod cfg;
-mod dhandler;
-mod minfo;
-mod norm;
-mod norm2;
-mod path;
-mod path2;
-mod pbuf;
-mod pred;
-mod pred2;
-mod resource;
-mod scope;
-mod url_ext;
-mod urls;
+pub mod cfg;
+pub mod dhandler;
+pub mod minfo;
+pub mod norm;
+pub mod norm2;
+pub mod path;
+pub mod path2;
+pub mod pbuf;
+pub mod pred;
+pub mod pred2;
+pub mod resource;
+pub mod scope;
+pub mod url_ext;
+pub mod urls;
//
use actix_web::{web, App, HttpRequest, HttpResponse};
diff --git a/examples/url-dispatch/src/minfo.rs b/examples/url-dispatch/src/minfo.rs
index 3ce4a6c..2222945 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, HttpServer, Result};
+use actix_web::{web, App, HttpRequest, Result};
fn index(req: HttpRequest) -> Result {
let v1: u8 = req.match_info().get("v1").unwrap().parse().unwrap();
@@ -8,7 +8,7 @@ fn index(req: HttpRequest) -> Result {
Ok(format!("Values {} {} {} {}", v1, v2, v3, v4))
}
-fn main() {
+pub fn main() {
App::new()
.route("/a/{v1}/{v2}/", web::get().to(index))
.route("", web::get().to(|| actix_web::HttpResponse::Ok()));
diff --git a/examples/url-dispatch/src/norm.rs b/examples/url-dispatch/src/norm.rs
index a1c8d4a..d396da4 100644
--- a/examples/url-dispatch/src/norm.rs
+++ b/examples/url-dispatch/src/norm.rs
@@ -1,10 +1,10 @@
//
-use actix_web::{middleware, web, App, HttpResponse};
+use actix_web::{middleware, web, App};
-fn main() {
+pub fn main() {
App::new()
.wrap(middleware::NormalizePath)
- .route("/", web::get().to(|| HttpResponse::Ok()));
+ .route("/", web::get().to(index));
}
//
diff --git a/examples/url-dispatch/src/norm2.rs b/examples/url-dispatch/src/norm2.rs
index cadfd35..1efc527 100644
--- a/examples/url-dispatch/src/norm2.rs
+++ b/examples/url-dispatch/src/norm2.rs
@@ -1,7 +1,7 @@
//
use actix_web::{http::Method, middleware, web, App};
-fn main() {
+pub fn main() {
App::new()
.wrap(middleware::NormalizePath)
.route("/resource/", web::get().to(index))
diff --git a/examples/url-dispatch/src/path.rs b/examples/url-dispatch/src/path.rs
index bc726c4..f3aea1a 100644
--- a/examples/url-dispatch/src/path.rs
+++ b/examples/url-dispatch/src/path.rs
@@ -6,7 +6,7 @@ fn index(info: web::Path<(String, u32)>) -> Result {
Ok(format!("Welcome {}! id: {}", info.0, info.1))
}
-fn main() {
+pub fn main() {
App::new().route(
"/{username}/{id}/index.html", // <- define path parameters
web::get().to(index),
diff --git a/examples/url-dispatch/src/pbuf.rs b/examples/url-dispatch/src/pbuf.rs
index 855d2e9..4ca0102 100644
--- a/examples/url-dispatch/src/pbuf.rs
+++ b/examples/url-dispatch/src/pbuf.rs
@@ -7,7 +7,7 @@ fn index(req: HttpRequest) -> Result {
Ok(format!("Path {:?}", path))
}
-fn main() {
+pub fn main() {
App::new().route(r"/a/{tail:.*}", web::get().to(index));
}
//
diff --git a/examples/url-dispatch/src/pred.rs b/examples/url-dispatch/src/pred.rs
index 8c75a2c..2617fa2 100644
--- a/examples/url-dispatch/src/pred.rs
+++ b/examples/url-dispatch/src/pred.rs
@@ -9,7 +9,7 @@ impl Guard for ContentTypeHeader {
}
}
-fn main() {
+pub fn main() {
App::new().route(
"",
web::route()
diff --git a/examples/url-dispatch/src/pred2.rs b/examples/url-dispatch/src/pred2.rs
index e56d6c2..68d13d7 100644
--- a/examples/url-dispatch/src/pred2.rs
+++ b/examples/url-dispatch/src/pred2.rs
@@ -1,7 +1,7 @@
//
use actix_web::{guard, web, App, HttpResponse};
-fn main() {
+pub fn main() {
App::new().route(
"/",
web::route()
diff --git a/examples/url-dispatch/src/resource.rs b/examples/url-dispatch/src/resource.rs
index f2d98db..a231856 100644
--- a/examples/url-dispatch/src/resource.rs
+++ b/examples/url-dispatch/src/resource.rs
@@ -1,11 +1,11 @@
//
-use actix_web::{http::Method, web, App, HttpRequest, HttpResponse};
+use actix_web::{web, App, HttpRequest, HttpResponse};
fn index(_req: HttpRequest) -> HttpResponse {
unimplemented!()
}
-fn main() {
+pub fn main() {
App::new()
.service(web::resource("/prefix").to(index))
.service(
diff --git a/examples/url-dispatch/src/scope.rs b/examples/url-dispatch/src/scope.rs
index 5bd4906..01795ef 100644
--- a/examples/url-dispatch/src/scope.rs
+++ b/examples/url-dispatch/src/scope.rs
@@ -5,10 +5,7 @@ fn show_users(_req: HttpRequest) -> HttpResponse {
unimplemented!()
}
-#[rustfmt::skip]
-fn main() {
- App::new()
- .service(web::scope("/users")
- .route("/show", web::get().to(show_users)));
+pub fn main() {
+ App::new().service(web::scope("/users").route("/show", web::get().to(show_users)));
}
//
diff --git a/examples/url-dispatch/src/url_ext.rs b/examples/url-dispatch/src/url_ext.rs
index eaa2503..8f1869c 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, Error, HttpRequest, HttpResponse, Responder};
+use actix_web::{web, App, HttpRequest, Responder};
fn index(req: HttpRequest) -> impl Responder {
let url = req.url_for("youtube", &["oHg5SJYRHA0"]).unwrap();
diff --git a/examples/url-dispatch/src/urls.rs b/examples/url-dispatch/src/urls.rs
index e1ab4dc..0ad653a 100644
--- a/examples/url-dispatch/src/urls.rs
+++ b/examples/url-dispatch/src/urls.rs
@@ -1,7 +1,5 @@
//
-use actix_web::{
- guard, http::header, http::Method, web, App, HttpRequest, HttpResponse, Result,
-};
+use actix_web::{guard, http::header, web, App, HttpRequest, HttpResponse, Result};
fn index(req: HttpRequest) -> Result {
let url = req.url_for("foo", &["1", "2", "3"])?; // <- generate url for "foo" resource