From 9ddf5a35500b5aa804dae26fad1ad29ae6c804d3 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 11 Mar 2018 09:28:22 -0700 Subject: [PATCH] better doc string for Either --- guide/src/qs_4.md | 16 ++++++++-------- src/handler.rs | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/guide/src/qs_4.md b/guide/src/qs_4.md index dd432d85a..be3d6cf33 100644 --- a/guide/src/qs_4.md +++ b/guide/src/qs_4.md @@ -253,23 +253,23 @@ use actix_web::{Either, Error, HttpResponse, httpcodes}; type RegisterResult = Either>>; 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 diff --git a/src/handler.rs b/src/handler.rs index cd16e164c..498da39de 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -46,8 +46,9 @@ pub trait Responder { /// /// type RegisterResult = Either>>; /// +/// /// 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)]