[−][src]Enum actix_web::Either
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
First branch of the type
Second branch of the type
Trait Implementations
impl<A: Debug, B: Debug> Debug for Either<A, B>
[src]
impl<A, B> FromRequest for Either<A, B> where
A: FromRequest + 'static,
B: FromRequest + 'static,
[src]
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>
The associated error which can be returned.
type Future = LocalBoxFuture<'static, Result<Self, Self::Error>>
Future that resolves to a Self
type Config = ()
Configuration for this extractor
pub fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
[src]
pub fn extract(req: &HttpRequest) -> Self::Future
[src]
pub fn configure<F>(f: F) -> Self::Config where
F: FnOnce(Self::Config) -> Self::Config,
[src]
F: FnOnce(Self::Config) -> Self::Config,
impl<A: PartialEq, B: PartialEq> PartialEq<Either<A, B>> for Either<A, B>
[src]
pub fn eq(&self, other: &Either<A, B>) -> bool
[src]
pub fn ne(&self, other: &Either<A, B>) -> bool
[src]
impl<A, B> Responder for Either<A, B> where
A: Responder,
B: Responder,
[src]
A: Responder,
B: Responder,
type Error = Error
The associated error which can be returned.
type Future = EitherResponder<A, B>
The future response value.
pub fn respond_to(self, req: &HttpRequest) -> Self::Future
[src]
pub fn with_status(self, status: StatusCode) -> CustomResponder<Self> where
Self: Sized,
[src]
Self: Sized,
pub 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,
[src]
Self: Sized,
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
V: IntoHeaderValue,
impl<A, B> StructuralPartialEq for Either<A, B>
[src]
Auto Trait Implementations
impl<A, B> RefUnwindSafe for Either<A, B> where
A: RefUnwindSafe,
B: RefUnwindSafe,
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for Either<A, B> where
A: Send,
B: Send,
A: Send,
B: Send,
impl<A, B> Sync for Either<A, B> where
A: Sync,
B: Sync,
A: Sync,
B: Sync,
impl<A, B> Unpin for Either<A, B> where
A: Unpin,
B: Unpin,
A: Unpin,
B: Unpin,
impl<A, B> UnwindSafe for Either<A, B> where
A: UnwindSafe,
B: UnwindSafe,
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,