logo

Enum actix_web::Either[][src]

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

Combines two different responder types into a single type

use actix_web::{Either, Error, HttpResponse};

type RegisterResult = Either<HttpResponse, Result<HttpResponse, Error>>;

fn index() -> RegisterResult {
    if is_a_variant() {
        // <- choose left variant
        Either::A(HttpResponse::BadRequest().body("Bad data"))
    } else {
        Either::B(
            // <- Right variant
            Ok(HttpResponse::Ok()
                .content_type("text/html")
                .body("Hello!"))
        )
    }
}

Variants

A(A)

Tuple Fields

0: A

First branch of the type

B(B)

Tuple Fields

0: B

Second branch of the type

Trait Implementations

Formats the value using the given formatter. Read more

Provides a mechanism for trying two extractors, a primary and a fallback. Useful for “polymorphic payloads” where, for example, a form might be JSON or URL encoded.

It is important to note that this extractor, by necessity, buffers the entire request payload as part of its implementation. Though, it does respect a PayloadConfig’s maximum size limit.

The associated error which can be returned.

Future that resolves to a Self

Configuration for this extractor

Convert request to a Self

Convert request to a Self Read more

Create and configure config instance.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The associated error which can be returned.

The future response value.

Convert itself to AsyncResult or Error.

Override a status code for a Responder. Read more

Add header to the Responder’s response. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more