1
0
mirror of https://github.com/actix/actix-website synced 2025-03-19 14:22:40 +01:00
2022-02-26 03:56:24 +00:00

30 lines
674 B
Rust

// <either>
use actix_web::{Either, Error, HttpResponse};
type RegisterResult = Either<HttpResponse, Result<&'static str, Error>>;
async fn index() -> RegisterResult {
if is_a_variant() {
// choose Left variant
Either::Left(HttpResponse::BadRequest().body("Bad data"))
} else {
// choose Right variant
Either::Right(Ok("Hello!"))
}
}
// </either>
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{web, App, HttpServer};
HttpServer::new(|| App::new().route("/", web::get().to(index)))
.bind(("127.0.0.1", 8080))?
.run()
.await
}
fn is_a_variant() -> bool {
true
}