Skip to content

Commit

Permalink
Type alias
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de>
  • Loading branch information
82marbag authored and Daniele Ahmed committed Oct 25, 2022
1 parent a17c083 commit b2b9272
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions rust-runtime/aws-smithy-http-server/src/operation/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ impl<S, P, Op, E, B> Layer<S> for UpgradeLayer<P, Op, E, B> {
}
}

/// An alias allowing for quick access to [`UpgradeLayer`]s target [`Service`].
pub type UpgradedService<P, Op, E, B, S> = <UpgradeLayer<P, Op, E, B> as Layer<S>>::Service;

/// A [`Service`] responsible for wrapping an operation [`Service`] accepting and returning Smithy
/// types, and converting it into a [`Service`] accepting and returning [`http`] types.
pub struct Upgrade<Protocol, Operation, Exts, B, S> {
Expand Down Expand Up @@ -227,6 +224,10 @@ pub trait Upgradable<Protocol, Operation, Exts, B, Plugin> {
fn upgrade(self, plugin: &Plugin) -> Route<B>;
}

type UpgradedService<Pl, P, Op, Exts, B, S, L> = <<Pl as Plugin<P, Op, S, L>>::Layer as Layer<
Upgrade<P, Op, Exts, B, <Pl as Plugin<P, Op, S, L>>::Service>,
>>::Service;

impl<P, Op, Exts, B, Pl, S, L, PollError> Upgradable<P, Op, Exts, B, Pl> for Operation<S, L>
where
// `Op` is used to specify the operation shape
Expand Down Expand Up @@ -257,8 +258,8 @@ where

// For `Route::new` for the resulting service
<Pl::Layer as Layer<Upgrade<P, Op, Exts, B, Pl::Service>>>::Service: Service<http::Request<B>, Error = Infallible>,
<<Pl as Plugin<P, Op, S, L>>::Layer as Layer<Upgrade<P, Op, Exts, B, <Pl as Plugin<P, Op, S, L>>::Service>>>::Service: Clone + Send + 'static,
<<<Pl as Plugin<P, Op, S, L>>::Layer as Layer<Upgrade<P, Op, Exts, B, <Pl as Plugin<P, Op, S, L>>::Service>>>::Service as Service<http::Request<B>>>::Future: Send + 'static,
UpgradedService<Pl, P, Op, Exts, B, S, L>: Clone + Send + 'static,
<UpgradedService<Pl, P, Op, Exts, B, S, L> as Service<http::Request<B>>>::Future: Send + 'static,
{
/// Takes the [`Operation<S, L>`](Operation), applies [`Plugin`], then applies [`UpgradeLayer`] to
/// the modified `S`, then finally applies the modified `L`.
Expand All @@ -284,16 +285,17 @@ pub struct FailOnMissingOperation;
impl<P, Op, Exts, B, Pl> Upgradable<P, Op, Exts, B, Pl> for FailOnMissingOperation
where
InternalFailureException: IntoResponse<P>,
P: Send + 'static,
P: 'static,
{
fn upgrade(self, _plugin: &Pl) -> Route<B> {
Route::new(MissingFailure { _protocol: PhantomData })
}
}

/// A [`Service`] which always returns an internal failure message and logs an error.
#[derive(Copy)]
pub struct MissingFailure<P> {
_protocol: PhantomData<P>,
_protocol: PhantomData<fn(P)>,
}

impl<P> Clone for MissingFailure<P> {
Expand Down

0 comments on commit b2b9272

Please sign in to comment.