1
0
mirror of https://github.com/actix/actix-website synced 2025-02-23 20:53:01 +01:00

36 lines
820 B
Rust
Raw Normal View History

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 =
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
}