1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 07:29:02 +02:00

review handlers section

This commit is contained in:
Nikolay Kim
2020-01-02 13:11:12 +06:00
parent e30c20016e
commit 4046b0b697
6 changed files with 28 additions and 104 deletions

View File

@ -1,23 +1,18 @@
// <either>
use actix_web::{Either, Error, HttpResponse};
use futures::future::{ok, Future};
type RegisterResult =
Either<HttpResponse, Box<dyn Future<Item = HttpResponse, Error = Error>>>;
type RegisterResult = Either<HttpResponse, Result<&'static str, Error>>;
fn index() -> RegisterResult {
if is_a_variant() {
// <- choose variant A
Either::A(HttpResponse::BadRequest().body("Bad data"))
} else {
Either::B(
// <- variant B
Box::new(ok(HttpResponse::Ok()
.content_type("text/html")
.body("Hello!".to_string()))),
)
// <- variant B
Either::B(Ok("Hello!"))
}
}
// </either>
fn main() {
use actix_web::{web, App, HttpServer};
@ -28,7 +23,6 @@ fn main() {
.run()
.unwrap();
}
// </either>
fn is_a_variant() -> bool {
true