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

30 lines
623 B
Rust

// <either>
use actix_web::{Either, Error, HttpResponse};
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 {
// <- variant B
Either::B(Ok("Hello!"))
}
}
// </either>
fn main() {
use actix_web::{web, App, HttpServer};
HttpServer::new(|| App::new().route("/", web::get().to(index)))
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
}
fn is_a_variant() -> bool {
true
}