1
0
mirror of https://github.com/actix/actix-website synced 2025-03-20 06:35:18 +01:00

30 lines
674 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() {
2022-02-26 03:56:24 +00:00
// choose Left variant
Either::Left(HttpResponse::BadRequest().body("Bad data"))
2019-06-15 16:37:08 -04:00
} else {
2022-02-26 03:56:24 +00:00
// choose Right variant
Either::Right(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)))
2022-02-26 03:56:24 +00: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
}