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

30 lines
702 B
Rust
Raw Normal View History

2019-06-15 16:37:08 -04:00
// <main>
use actix_web::{web, App, Either, Error, HttpRequest, HttpResponse};
use futures::future::{ok, Future};
type RegisterResult =
Either<HttpResponse, Box<Future<Item = HttpResponse, Error = Error>>>;
fn index(_req: HttpRequest) -> 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(format!("Hello!")))),
)
}
}
fn main() {
App::new().route("/", web::get().to(index));
}
// </main>
fn is_a_variant() -> bool {
true
}