2019-06-15 16:37:08 -04:00
|
|
|
fn is_error() -> bool {
|
2019-06-20 02:04:22 -04:00
|
|
|
false
|
2019-06-15 16:37:08 -04:00
|
|
|
}
|
|
|
|
|
2019-06-20 02:04:22 -04:00
|
|
|
// <async-stream>
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{error, Error, HttpResponse};
|
2019-06-15 16:37:08 -04:00
|
|
|
use futures::future::{result, Future};
|
|
|
|
|
2019-06-28 13:31:30 -04:00
|
|
|
fn index() -> Result<Box<Future<Item = HttpResponse, Error = Error>>, Error> {
|
2019-06-15 16:37:08 -04:00
|
|
|
if is_error() {
|
|
|
|
Err(error::ErrorBadRequest("bad request"))
|
|
|
|
} else {
|
|
|
|
Ok(Box::new(result(Ok(HttpResponse::Ok()
|
|
|
|
.content_type("text/html")
|
2019-06-20 02:04:22 -04:00
|
|
|
.body("Hello!")))))
|
2019-06-15 16:37:08 -04:00
|
|
|
}
|
|
|
|
}
|
2019-06-20 02:04:22 -04:00
|
|
|
// </async-stream>
|
2019-06-15 16:37:08 -04:00
|
|
|
|
|
|
|
pub fn main() {
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{web, App, HttpServer};
|
|
|
|
|
2019-06-20 02:04:22 -04:00
|
|
|
HttpServer::new(|| App::new().route("/", web::to_async(index)))
|
|
|
|
.bind("127.0.0.1:8088")
|
|
|
|
.unwrap()
|
|
|
|
.run()
|
|
|
|
.unwrap();
|
2019-06-15 16:37:08 -04:00
|
|
|
}
|