pub enum Either<A, B> {
Left(A),
Right(B),
}
Expand description
An Enum representing a value of one of two possible types.
Either<A, B>
is particularly useful in service composition and layered architectures.
Either
allows for conditional inclusion of layers in a service stack:
impl<T> SvcC<T> {
fn layer<C>() -> impl FactoryLayer<C, T, Factory = Self> {
layer_fn(|_: &C, inner| SvcC { inner })
}
fn opt_layer<C>(enabled: bool) -> Option<impl FactoryLayer<C, T, Factory = Self>> {
if enabled {
Some(layer_fn(|_: &C, inner| SvcC { inner }))
} else {
None
}
}
}
let stack = FactoryStack::new(config)
.push(SvcAFactory::layer())
.push(SvcBFactory::layer())
.push(SvcC::opt_layer(true)); // Conditionally include SvcC
This pattern enables runtime control over the service composition, making it possible to dynamically include or exclude certain layers based on configuration or runtime conditions.
Variants§
Implementations§
Source§impl<A, B> Either<A, B>
impl<A, B> Either<A, B>
Source§impl<T> Either<T, T>
impl<T> Either<T, T>
pub fn into_inner(self) -> T
Trait Implementations§
Source§impl<A, B> AsyncMakeService for Either<A, B>where
A: AsyncMakeService,
B: AsyncMakeService,
impl<A, B> AsyncMakeService for Either<A, B>where
A: AsyncMakeService,
B: AsyncMakeService,
Source§type Service = Either<<A as AsyncMakeService>::Service, <B as AsyncMakeService>::Service>
type Service = Either<<A as AsyncMakeService>::Service, <B as AsyncMakeService>::Service>
The type of service this factory creates.
Source§type Error = Either<<A as AsyncMakeService>::Error, <B as AsyncMakeService>::Error>
type Error = Either<<A as AsyncMakeService>::Error, <B as AsyncMakeService>::Error>
The type of error that can occur during service creation.
Source§impl<A: Error, B: Error> Error for Either<A, B>
impl<A: Error, B: Error> Error for Either<A, B>
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl<C, F, FLA, FLB> FactoryLayer<C, F> for Either<FLA, FLB>where
FLA: FactoryLayer<C, F>,
FLB: FactoryLayer<C, F>,
impl<C, F, FLA, FLB> FactoryLayer<C, F> for Either<FLA, FLB>where
FLA: FactoryLayer<C, F>,
FLB: FactoryLayer<C, F>,
Source§impl<A, B> MakeService for Either<A, B>where
A: MakeService,
B: MakeService,
impl<A, B> MakeService for Either<A, B>where
A: MakeService,
B: MakeService,
Source§type Service = Either<<A as MakeService>::Service, <B as MakeService>::Service>
type Service = Either<<A as MakeService>::Service, <B as MakeService>::Service>
The type of service this factory creates.
Source§type Error = Either<<A as MakeService>::Error, <B as MakeService>::Error>
type Error = Either<<A as MakeService>::Error, <B as MakeService>::Error>
The type of error that can occur during service creation.
Auto Trait Implementations§
impl<A, B> Freeze for Either<A, B>
impl<A, B> RefUnwindSafe for Either<A, B>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for Either<A, B>
impl<A, B> Sync for Either<A, B>
impl<A, B> Unpin for Either<A, B>
impl<A, B> UnwindSafe for Either<A, B>where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, Request, Response, E> BoxService<Request, Response, E> for Twhere
T: Service<Request, Response = Response, Error = E> + 'static,
Request: 'static,
impl<T, Request, Response, E> BoxService<Request, Response, E> for Twhere
T: Service<Request, Response = Response, Error = E> + 'static,
Request: 'static,
fn into_boxed(self) -> BoxedService<Request, Response, E>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more