Enum actix_web::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)
First branch of the type
B(B)
Second branch of the type
Trait Implementations
impl<A, B> FromRequest for Either<A, B> where
A: FromRequest + 'static,
B: FromRequest + 'static,
impl<A, B> FromRequest for Either<A, B> where
A: FromRequest + 'static,
B: FromRequest + 'static,
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.
type Error = EitherExtractError<A::Error, B::Error>
type Error = EitherExtractError<A::Error, B::Error>
The associated error which can be returned.
type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>
type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>
Future that resolves to a Self
Convert request to a Self
Convert request to a Self Read more
type Future = EitherResponder<A, B>
type Future = EitherResponder<A, B>
The future response value.
Convert itself to AsyncResult
or Error
.
Override a status code for a Responder. Read more
fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self> where
Self: Sized,
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self> where
Self: Sized,
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
Add header to the Responder’s response. Read more
Auto Trait Implementations
impl<A, B> RefUnwindSafe for Either<A, B> where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> UnwindSafe for Either<A, B> where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
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