1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

better doc string for Either

This commit is contained in:
Nikolay Kim 2018-03-11 09:28:22 -07:00
parent 6c709b33cc
commit 9ddf5a3550
2 changed files with 11 additions and 9 deletions

View File

@ -253,23 +253,23 @@ use actix_web::{Either, Error, HttpResponse, httpcodes};
type RegisterResult = Either<HttpResponse, Box<Future<Item=HttpResponse, Error=Error>>>;
fn index(req: HttpRequest) -> RegisterResult {
if true { // <- choose variant A
if is_a_variant() { // <- choose variant A
Either::A(
httpcodes::HttpBadRequest.with_body("Bad data"))
} else {
Either::B( // <- variant B
Either::B( // <- variant B
result(HttpResponse::Ok()
.content_type("text/html")
.body(format!("Hello!"))
.map_err(|e| e.into())).responder())
}
}
fn main() {
Application::new()
.resource("/register", |r| r.f(index))
.finish();
}
# fn is_a_variant() -> bool { true }
# fn main() {
# Application::new()
# .resource("/register", |r| r.f(index))
# .finish();
# }
```
## Tokio core handle

View File

@ -46,8 +46,9 @@ pub trait Responder {
///
/// type RegisterResult = Either<HttpResponse, Box<Future<Item=HttpResponse, Error=Error>>>;
///
///
/// fn index(req: HttpRequest) -> RegisterResult {
/// if true { // <- choose variant A
/// if is_a_variant() { // <- choose variant A
/// Either::A(
/// httpcodes::HttpBadRequest.with_body("Bad data"))
/// } else {
@ -58,6 +59,7 @@ pub trait Responder {
/// .map_err(|e| e.into())).responder())
/// }
/// }
/// # fn is_a_variant() -> bool { true }
/// # fn main() {}
/// ```
#[derive(Debug)]