mirror of
https://github.com/actix/actix-website
synced 2025-02-23 20:53:01 +01:00
25 lines
567 B
Rust
25 lines
567 B
Rust
|
fn is_error() -> bool {
|
||
|
true
|
||
|
}
|
||
|
|
||
|
// <main>
|
||
|
use actix_web::{error, App, Error, HttpRequest, HttpResponse};
|
||
|
use futures::future::{result, Future};
|
||
|
|
||
|
fn index(
|
||
|
_req: &HttpRequest,
|
||
|
) -> Result<Box<Future<Item = HttpResponse, Error = Error>>, Error> {
|
||
|
if is_error() {
|
||
|
Err(error::ErrorBadRequest("bad request"))
|
||
|
} else {
|
||
|
Ok(Box::new(result(Ok(HttpResponse::Ok()
|
||
|
.content_type("text/html")
|
||
|
.body(format!("Hello!"))))))
|
||
|
}
|
||
|
}
|
||
|
// </main>
|
||
|
|
||
|
pub fn main() {
|
||
|
App::new().resource("/", |r| r.route().f(index)).finish();
|
||
|
}
|