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

30 lines
656 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
2020-01-02 13:11:12 +06:00
type RegisterResult = Either<HttpResponse, Result<&'static str, Error>>;
2019-06-15 16:37:08 -04:00
2020-09-12 16:21:54 +01:00
async 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 {
2020-01-02 13:11:12 +06:00
// <- variant B
Either::B(Ok("Hello!"))
2019-06-15 16:37:08 -04:00
}
}
2020-01-02 13:11:12 +06:00
// </either>
2019-06-15 16:37:08 -04:00
2020-09-12 16:21:54 +01:00
#[actix_web::main]
async fn main() -> std::io::Result<()> {
2019-06-28 13:31:30 -04:00
use actix_web::{web, App, HttpServer};
HttpServer::new(|| App::new().route("/", web::get().to(index)))
2020-09-12 16:21:54 +01:00
.bind("127.0.0.1:8080")?
2019-06-28 13:31:30 -04:00
.run()
2020-09-12 16:21:54 +01:00
.await
2019-06-15 16:37:08 -04:00
}
fn is_a_variant() -> bool {
true
}