Enum ntex::util::Either[][src]

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

Combines two different futures, streams, or sinks having the same associated types into a single type.

Variants

Left(A)

First branch of the type

Right(B)

Second branch of the type

Implementations

impl<A, B> Either<A, B>[src]

pub fn is_left(&self) -> bool[src]

Return true if the value is the Left variant.

pub fn is_right(&self) -> bool[src]

Return true if the value is the Right variant.

pub fn left(self) -> Option<A>[src]

Convert the left side of Either<L, R> to an Option<L>.

pub fn right(self) -> Option<B>[src]

Convert the right side of Either<L, R> to an Option<R>.

pub fn as_ref(&self) -> Either<&A, &B>

Notable traits for Either<A, B>

impl<A, B> Future for Either<A, B> where
    B: Future<Output = <A as Future>::Output>,
    A: Future
type Output = <A as Future>::Output;
[src]

Convert &Either<L, R> to Either<&L, &R>.

pub fn as_mut(&mut self) -> Either<&mut A, &mut B>

Notable traits for Either<A, B>

impl<A, B> Future for Either<A, B> where
    B: Future<Output = <A as Future>::Output>,
    A: Future
type Output = <A as Future>::Output;
[src]

Convert &mut Either<L, R> to Either<&mut L, &mut R>.

impl<A, B, T> Either<(T, A), (T, B)>[src]

pub fn factor_first(self) -> (T, Either<A, B>)[src]

Factor out a homogeneous type from an either of pairs.

Here, the homogeneous type is the first element of the pairs.

impl<A, B, T> Either<(A, T), (B, T)>[src]

pub fn factor_second(self) -> (Either<A, B>, T)[src]

Factor out a homogeneous type from an either of pairs.

Here, the homogeneous type is the second element of the pairs.

impl<T> Either<T, T>[src]

pub fn into_inner(self) -> T[src]

Extract the value of an either over two equivalent types.

Trait Implementations

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

pub fn clone(&self) -> Either<A, B>

Notable traits for Either<A, B>

impl<A, B> Future for Either<A, B> where
    B: Future<Output = <A as Future>::Output>,
    A: Future
type Output = <A as Future>::Output;
[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>[src]

Formats the value using the given formatter. Read more

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

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>[src]

Formats the value using the given formatter. Read more

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

Either implements Error if both A and B implement it.

fn source(&self) -> Option<&(dyn Error + 'static)>1.30.0[src]

The lower-level source of this error, if any. Read more

fn backtrace(&self) -> Option<&Backtrace>[src]

🔬 This is a nightly-only experimental API. (backtrace)

Returns a stack backtrace, if available, of where this error occurred. Read more

fn description(&self) -> &str1.0.0[src]

👎 Deprecated since 1.42.0:

use the Display impl or to_string()

fn cause(&self) -> Option<&dyn Error>1.0.0[src]

👎 Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

impl From<Either<Error, Error>> for SendRequestError[src]

fn from(err: Either<Error, Error>) -> Self[src]

Performs the conversion.

impl From<Either<ParseError, Error>> for SendRequestError[src]

fn from(err: Either<ParseError, Error>) -> Self[src]

Performs the conversion.

impl From<Either<PayloadError, Error>> for PayloadError[src]

fn from(err: Either<PayloadError, Error>) -> Self[src]

Performs the conversion.

impl<A, B> Future for Either<A, B> where
    B: Future<Output = <A as Future>::Output>,
    A: Future
[src]

type Output = <A as Future>::Output

The type of value produced on completion.

pub fn poll(
    self: Pin<&mut Either<A, B>>,
    cx: &mut Context<'_>
) -> Poll<<Either<A, B> as Future>::Output>
[src]

Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

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

pub fn hash<__H>(&self, state: &mut __H) where
    __H: Hasher
[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

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

pub fn cmp(&self, other: &Either<A, B>) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

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

pub fn eq(&self, other: &Either<A, B>) -> bool[src]

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

pub fn ne(&self, other: &Either<A, B>) -> bool[src]

This method tests for !=.

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

pub fn partial_cmp(&self, other: &Either<A, B>) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

Combines two different responder types into a single type

use ntex::{web::HttpResponse, util::Either};

fn index() -> Either<HttpResponse, &'static str> {
    if is_a_variant() {
        // <- choose left variant
        Either::Left(HttpResponse::BadRequest().body("Bad data"))
    } else {
        // <- Right variant
        Either::Right("Hello!")
    }
}

type Error = Err::Container

The associated error which can be returned.

type Future = Either<A::Future, B::Future>

The future response value.

fn respond_to(self, req: &HttpRequest) -> Self::Future[src]

Convert itself to AsyncResult or Error.

fn with_status(self, status: StatusCode) -> CustomResponder<Self, Err> where
    Self: Sized
[src]

Override a status code for a Responder. Read more

fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self, Err> where
    Self: Sized,
    HeaderName: TryFrom<K>,
    HeaderValue: TryFrom<V>,
    <HeaderName as TryFrom<K>>::Error: Into<HttpError>,
    <HeaderValue as TryFrom<V>>::Error: Into<HttpError>, 
[src]

Add header to the Responder’s response. Read more

impl<A, B, Err> WebResponseError<Err> for Either<A, B> where
    A: WebResponseError<Err>,
    B: WebResponseError<Err>,
    Err: ErrorRenderer
[src]

fn status_code(&self) -> StatusCode[src]

Response’s status code Read more

fn error_response(&self, req: &HttpRequest) -> HttpResponse[src]

Generate response for error Read more

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

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

impl<A, B> StructuralEq for Either<A, B>[src]

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> CallHasher for T where
    T: Hash + ?Sized
[src]

pub default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64 where
    H: Hash + ?Sized,
    B: BuildHasher
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

pub fn equivalent(&self, key: &K) -> bool[src]

Compare self to key and return true if they are equal.

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> FutureExt for T where
    T: Future + ?Sized

fn map<U, F>(self, f: F) -> Map<Self, F> where
    F: FnOnce(Self::Output) -> U, 

Map this future’s output to a different type, returning a new future of the resulting type. Read more

fn map_into<U>(self) -> MapInto<Self, U> where
    Self::Output: Into<U>, 

Map this future’s output to a different type, returning a new future of the resulting type. Read more

fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> where
    F: FnOnce(Self::Output) -> Fut,
    Fut: Future

Chain on a computation for when a future finished, passing the result of the future to the provided closure f. Read more

fn left_future<B>(self) -> Either<Self, B> where
    B: Future<Output = Self::Output>, 

Wrap this future in an Either future, making it the left-hand variant of that Either. Read more

fn right_future<A>(self) -> Either<A, Self> where
    A: Future<Output = Self::Output>, 

Wrap this future in an Either future, making it the right-hand variant of that Either. Read more

fn into_stream(self) -> IntoStream<Self>

Convert this future into a single element stream. Read more

fn flatten(self) -> Flatten<Self> where
    Self::Output: Future

Flatten the execution of this future when the output of this future is itself another future. Read more

fn flatten_stream(self) -> FlattenStream<Self> where
    Self::Output: Stream

Flatten the execution of this future when the successful result of this future is a stream. Read more

fn fuse(self) -> Fuse<Self>

Fuse a future such that poll will never again be called once it has completed. This method can be used to turn any Future into a FusedFuture. Read more

fn inspect<F>(self, f: F) -> Inspect<Self, F> where
    F: FnOnce(&Self::Output), 

Do something with the output of a future before passing it on. Read more

fn catch_unwind(self) -> CatchUnwind<Self> where
    Self: UnwindSafe

Catches unwinding panics while polling the future. Read more

fn shared(self) -> Shared<Self> where
    Self::Output: Clone

Create a cloneable handle to this future where all handles will resolve to the same result. Read more

fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)

Turn this future into a future that yields () on completion and sends its output to another future on a separate task. Read more

fn boxed<'a>(
    self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a + Send, Global>> where
    Self: Send + 'a, 

Wrap the future in a Box, pinning it. Read more

fn boxed_local<'a>(
    self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>> where
    Self: 'a, 

Wrap the future in a Box, pinning it. Read more

fn unit_error(self) -> UnitError<Self>

fn never_error(self) -> NeverError<Self>

fn poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
    Self: Unpin

A convenience for calling Future::poll on Unpin future types.

fn now_or_never(self) -> Option<Self::Output>

Evaluates and consumes the future, returning the resulting output if the future is ready after the first call to Future::poll. Read more

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

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

fn in_current_span(self) -> Instrumented<Self>[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<F> IntoFuture for F where
    F: Future
[src]

type Output = <F as Future>::Output

🔬 This is a nightly-only experimental API. (into_future)

The output that the future will produce on completion.

type Future = F

🔬 This is a nightly-only experimental API. (into_future)

Which kind of future are we turning this into?

pub fn into_future(self) -> <F as IntoFuture>::Future[src]

🔬 This is a nightly-only experimental API. (into_future)

Creates a future from a value.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

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]

Performs the conversion.

impl<F, T, E> TryFuture for F where
    F: Future<Output = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

pub fn try_poll(
    self: Pin<&mut F>,
    cx: &mut Context<'_>
) -> Poll<<F as Future>::Output>
[src]

Poll this TryFuture as if it were a Future. Read more

impl<Fut> TryFutureExt for Fut where
    Fut: TryFuture + ?Sized

fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok> where
    Self::Ok: Sink<Item>,
    <Self::Ok as Sink<Item>>::Error == Self::Error

Flattens the execution of this future when the successful result of this future is a Sink. Read more

fn map_ok<T, F>(self, f: F) -> MapOk<Self, F> where
    F: FnOnce(Self::Ok) -> T, 

Maps this future’s success value to a different value. Read more

fn map_ok_or_else<T, E, F>(self, e: E, f: F) -> MapOkOrElse<Self, F, E> where
    F: FnOnce(Self::Ok) -> T,
    E: FnOnce(Self::Error) -> T, 

Maps this future’s success value to a different value, and permits for error handling resulting in the same type. Read more

fn map_err<E, F>(self, f: F) -> MapErr<Self, F> where
    F: FnOnce(Self::Error) -> E, 

Maps this future’s error value to a different value. Read more

fn err_into<E>(self) -> ErrInto<Self, E> where
    Self::Error: Into<E>, 

Maps this future’s Error to a new error type using the Into trait. Read more

fn ok_into<U>(self) -> OkInto<Self, U> where
    Self::Ok: Into<U>, 

Maps this future’s Ok to a new type using the Into trait. Read more

fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F> where
    F: FnOnce(Self::Ok) -> Fut,
    Fut: TryFuture<Error = Self::Error>, 

Executes another future after this one resolves successfully. The success value is passed to a closure to create this subsequent future. Read more

fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F> where
    F: FnOnce(Self::Error) -> Fut,
    Fut: TryFuture<Ok = Self::Ok>, 

Executes another future if this one resolves to an error. The error value is passed to a closure to create this subsequent future. Read more

fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F> where
    F: FnOnce(&Self::Ok), 

Do something with the success value of a future before passing it on. Read more

fn inspect_err<F>(self, f: F) -> InspectErr<Self, F> where
    F: FnOnce(&Self::Error), 

Do something with the error value of a future before passing it on. Read more

fn try_flatten(self) -> TryFlatten<Self, Self::Ok> where
    Self::Ok: TryFuture,
    <Self::Ok as TryFuture>::Error == Self::Error

Flatten the execution of this future when the successful result of this future is another future. Read more

fn try_flatten_stream(self) -> TryFlattenStream<Self> where
    Self::Ok: TryStream,
    <Self::Ok as TryStream>::Error == Self::Error

Flatten the execution of this future when the successful result of this future is a stream. Read more

fn unwrap_or_else<F>(self, f: F) -> UnwrapOrElse<Self, F> where
    F: FnOnce(Self::Error) -> Self::Ok

Unwraps this future’s output, producing a future with this future’s Ok type as its Output type. Read more

fn into_future(self) -> IntoFuture<Self>

Wraps a TryFuture into a type that implements Future. Read more

fn try_poll_unpin(
    &mut self,
    cx: &mut Context<'_>
) -> Poll<Result<Self::Ok, Self::Error>> where
    Self: Unpin

A convenience method for calling TryFuture::try_poll on Unpin future types. Read more

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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]

Performs the conversion.