mirror of
https://github.com/actix/actix-website
synced 2025-06-29 16:24:58 +02:00
moves individual examples to pub mods to force building and have less dead_code
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
use actix_web::{web, App};
|
||||
// <helpers>
|
||||
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))?)
|
||||
}
|
||||
// </helpers>
|
||||
pub fn main() {
|
||||
App::new().route("/", web::get().to(index));
|
||||
}
|
||||
|
@ -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};
|
||||
// <response-error>
|
||||
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" })
|
||||
}
|
||||
// </response-error>
|
||||
fn main() {}
|
||||
pub fn main() {
|
||||
App::new().route("/", web::get().to(index));
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use actix_web::{web, App};
|
||||
// <override>
|
||||
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)
|
||||
}
|
||||
// </override>
|
||||
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)
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use actix_web::{web, App, HttpRequest};
|
||||
// <recommend-one>
|
||||
use actix_web::{error, http, HttpResponse};
|
||||
use failure::Fail;
|
||||
@ -18,3 +19,12 @@ impl error::ResponseError for UserError {
|
||||
}
|
||||
}
|
||||
// </recommend-one>
|
||||
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(),
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use actix_web::App;
|
||||
// <recommend-two>
|
||||
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!")
|
||||
}
|
||||
// </recommend-two>
|
||||
pub fn main() {
|
||||
App::new().route("/", web::get().to(index));
|
||||
}
|
||||
|
Reference in New Issue
Block a user