Enum actix_web::Either [] [src]

pub enum Either<A, B> {
    A(A),
    B(B),
}

Combines two different responder types into a single type

use actix_web::AsyncResponder;
use futures::future::result;
use actix_web::{Either, Error, HttpRequest, HttpResponse, httpcodes};

type RegisterResult = Either<HttpResponse, Box<Future<Item=HttpResponse, Error=Error>>>;


fn index(req: HttpRequest) -> RegisterResult {
    if is_a_variant() { // <- choose variant A
        Either::A(
            httpcodes::HttpBadRequest.with_body("Bad data"))
    } else {
        Either::B(      // <- variant B
            result(HttpResponse::Ok()
                   .content_type("text/html")
                   .body(format!("Hello!"))
                   .map_err(|e| e.into())).responder())
    }
}

Variants

First branch of the type

Second branch of the type

Trait Implementations

impl<A: Debug, B: Debug> Debug for Either<A, B>
[src]

[src]

Formats the value using the given formatter. Read more

impl<A, B> Responder for Either<A, B> where
    A: Responder,
    B: Responder
[src]

The associated item which can be returned.

The associated error which can be returned.

[src]

Convert itself to Reply or Error.

Auto Trait Implementations

impl<A, B> Send for Either<A, B> where
    A: Send,
    B: Send

impl<A, B> Sync for Either<A, B> where
    A: Sync,
    B: Sync