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
A(A)
First branch of the type
B(B)
Second branch of the type
Trait Implementations
impl<A: Debug, B: Debug> Debug for Either<A, B>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<A, B> Responder for Either<A, B> where
A: Responder,
B: Responder,
[src]
A: Responder,
B: Responder,
type Item = Reply
The associated item which can be returned.
type Error = Error
The associated error which can be returned.
fn respond_to(self, req: HttpRequest) -> Result<Reply, Error>
[src]
Convert itself to Reply
or Error
.