mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
better doc string for Either
This commit is contained in:
parent
6c709b33cc
commit
9ddf5a3550
@ -253,23 +253,23 @@ use actix_web::{Either, Error, HttpResponse, httpcodes};
|
|||||||
type RegisterResult = Either<HttpResponse, Box<Future<Item=HttpResponse, Error=Error>>>;
|
type RegisterResult = Either<HttpResponse, Box<Future<Item=HttpResponse, Error=Error>>>;
|
||||||
|
|
||||||
fn index(req: HttpRequest) -> RegisterResult {
|
fn index(req: HttpRequest) -> RegisterResult {
|
||||||
if true { // <- choose variant A
|
if is_a_variant() { // <- choose variant A
|
||||||
Either::A(
|
Either::A(
|
||||||
httpcodes::HttpBadRequest.with_body("Bad data"))
|
httpcodes::HttpBadRequest.with_body("Bad data"))
|
||||||
} else {
|
} else {
|
||||||
Either::B( // <- variant B
|
Either::B( // <- variant B
|
||||||
result(HttpResponse::Ok()
|
result(HttpResponse::Ok()
|
||||||
.content_type("text/html")
|
.content_type("text/html")
|
||||||
.body(format!("Hello!"))
|
.body(format!("Hello!"))
|
||||||
.map_err(|e| e.into())).responder())
|
.map_err(|e| e.into())).responder())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# fn is_a_variant() -> bool { true }
|
||||||
fn main() {
|
# fn main() {
|
||||||
Application::new()
|
# Application::new()
|
||||||
.resource("/register", |r| r.f(index))
|
# .resource("/register", |r| r.f(index))
|
||||||
.finish();
|
# .finish();
|
||||||
}
|
# }
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tokio core handle
|
## Tokio core handle
|
||||||
|
@ -46,8 +46,9 @@ pub trait Responder {
|
|||||||
///
|
///
|
||||||
/// type RegisterResult = Either<HttpResponse, Box<Future<Item=HttpResponse, Error=Error>>>;
|
/// type RegisterResult = Either<HttpResponse, Box<Future<Item=HttpResponse, Error=Error>>>;
|
||||||
///
|
///
|
||||||
|
///
|
||||||
/// fn index(req: HttpRequest) -> RegisterResult {
|
/// fn index(req: HttpRequest) -> RegisterResult {
|
||||||
/// if true { // <- choose variant A
|
/// if is_a_variant() { // <- choose variant A
|
||||||
/// Either::A(
|
/// Either::A(
|
||||||
/// httpcodes::HttpBadRequest.with_body("Bad data"))
|
/// httpcodes::HttpBadRequest.with_body("Bad data"))
|
||||||
/// } else {
|
/// } else {
|
||||||
@ -58,6 +59,7 @@ pub trait Responder {
|
|||||||
/// .map_err(|e| e.into())).responder())
|
/// .map_err(|e| e.into())).responder())
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
|
/// # fn is_a_variant() -> bool { true }
|
||||||
/// # fn main() {}
|
/// # fn main() {}
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
Loading…
Reference in New Issue
Block a user