mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
moves individual examples to pub mods to force building and have less dead_code
This commit is contained in:
@ -5,7 +5,7 @@ fn index(_req: HttpRequest) -> impl Responder {
|
||||
}
|
||||
|
||||
// <default>
|
||||
fn main() {
|
||||
pub fn main() {
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::get().to(index)))
|
||||
.default_service(
|
||||
|
@ -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;
|
||||
|
||||
// <main>
|
||||
use actix_web::{web, App, HttpRequest, HttpResponse};
|
||||
|
@ -1,5 +1,5 @@
|
||||
// <minfo>
|
||||
use actix_web::{web, App, HttpRequest, HttpServer, Result};
|
||||
use actix_web::{web, App, HttpRequest, Result};
|
||||
|
||||
fn index(req: HttpRequest) -> Result<String> {
|
||||
let v1: u8 = req.match_info().get("v1").unwrap().parse().unwrap();
|
||||
@ -8,7 +8,7 @@ fn index(req: HttpRequest) -> Result<String> {
|
||||
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()));
|
||||
|
@ -1,10 +1,10 @@
|
||||
// <norm>
|
||||
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));
|
||||
}
|
||||
// </norm>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// <norm>
|
||||
use actix_web::{http::Method, middleware, web, App};
|
||||
|
||||
fn main() {
|
||||
pub fn main() {
|
||||
App::new()
|
||||
.wrap(middleware::NormalizePath)
|
||||
.route("/resource/", web::get().to(index))
|
||||
|
@ -6,7 +6,7 @@ fn index(info: web::Path<(String, u32)>) -> Result<String> {
|
||||
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),
|
||||
|
@ -7,7 +7,7 @@ fn index(req: HttpRequest) -> Result<String> {
|
||||
Ok(format!("Path {:?}", path))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
pub fn main() {
|
||||
App::new().route(r"/a/{tail:.*}", web::get().to(index));
|
||||
}
|
||||
// </pbuf>
|
||||
|
@ -9,7 +9,7 @@ impl Guard for ContentTypeHeader {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
pub fn main() {
|
||||
App::new().route(
|
||||
"",
|
||||
web::route()
|
||||
|
@ -1,7 +1,7 @@
|
||||
// <pred>
|
||||
use actix_web::{guard, web, App, HttpResponse};
|
||||
|
||||
fn main() {
|
||||
pub fn main() {
|
||||
App::new().route(
|
||||
"/",
|
||||
web::route()
|
||||
|
@ -1,11 +1,11 @@
|
||||
// <resource>
|
||||
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(
|
||||
|
@ -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)));
|
||||
}
|
||||
// </scope>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// <ext>
|
||||
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();
|
||||
|
@ -1,7 +1,5 @@
|
||||
// <url>
|
||||
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<HttpResponse> {
|
||||
let url = req.url_for("foo", &["1", "2", "3"])?; // <- generate url for "foo" resource
|
||||
|
Reference in New Issue
Block a user