2019-06-20 02:04:22 -04:00
|
|
|
// <either>
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{Either, Error, HttpResponse};
|
2019-06-15 16:37:08 -04:00
|
|
|
use futures::future::{ok, Future};
|
|
|
|
|
|
|
|
type RegisterResult =
|
2019-07-29 12:44:00 +02:00
|
|
|
Either<HttpResponse, Box<dyn Future<Item = HttpResponse, Error = Error>>>;
|
2019-06-15 16:37:08 -04:00
|
|
|
|
2019-06-28 13:31:30 -04:00
|
|
|
fn index() -> RegisterResult {
|
2019-06-15 16:37:08 -04:00
|
|
|
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")
|
2019-06-22 09:18:08 -04:00
|
|
|
.body("Hello!".to_string()))),
|
2019-06-15 16:37:08 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{web, App, HttpServer};
|
|
|
|
|
|
|
|
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
|
|
|
.bind("127.0.0.1:8088")
|
|
|
|
.unwrap()
|
|
|
|
.run()
|
|
|
|
.unwrap();
|
2019-06-15 16:37:08 -04:00
|
|
|
}
|
2019-06-20 02:04:22 -04:00
|
|
|
// </either>
|
2019-06-15 16:37:08 -04:00
|
|
|
|
|
|
|
fn is_a_variant() -> bool {
|
|
|
|
true
|
|
|
|
}
|