-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route::new in upgrade #1891
Route::new in upgrade #1891
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ use crate::{ | |
plugin::Plugin, | ||
request::{FromParts, FromRequest}, | ||
response::IntoResponse, | ||
routing::Route, | ||
runtime_error::InternalFailureException, | ||
}; | ||
|
||
|
@@ -225,7 +226,7 @@ pub trait Upgradable<Protocol, Operation, Exts, B, Plugin> { | |
type Service: Service<http::Request<B>, Response = http::Response<BoxBody>>; | ||
82marbag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Performs an upgrade from a representation of an operation to a HTTP [`Service`](tower::Service). | ||
fn upgrade(self, plugin: &Plugin) -> Self::Service; | ||
fn upgrade(self, plugin: &Plugin) -> Route<B>; | ||
} | ||
|
||
impl<P, Op, Exts, B, Pl, S, L, PollError> Upgradable<P, Op, Exts, B, Pl> for Operation<S, L> | ||
|
@@ -255,17 +256,22 @@ where | |
// The signature of the output is correct | ||
<Pl::Layer as Layer<Upgrade<P, Op, Exts, B, Pl::Service>>>::Service: | ||
Service<http::Request<B>, Response = http::Response<BoxBody>>, | ||
|
||
// For `Route::new` for the resulting service | ||
<Pl::Layer as Layer<Upgrade<P, Op, Exts, B, Pl::Service>>>::Service: tower::Service<http::Request<B>, Error = std::convert::Infallible>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have Same for line 261. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth adding a type alias to reduce the length of these. |
||
<<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 tower::Service<http::Request<B>>>::Future: Send + 'static, | ||
{ | ||
type Service = <Pl::Layer as Layer<Upgrade<P, Op, Exts, B, Pl::Service>>>::Service; | ||
|
||
/// Takes the [`Operation<S, L>`](Operation), applies [`Plugin`], then applies [`UpgradeLayer`] to | ||
/// the modified `S`, then finally applies the modified `L`. | ||
/// | ||
/// The composition is made explicit in the method constraints and return type. | ||
fn upgrade(self, plugin: &Pl) -> Self::Service { | ||
fn upgrade(self, plugin: &Pl) -> Route<B> { | ||
let mapped = plugin.map(self); | ||
let layer = Stack::new(UpgradeLayer::new(), mapped.layer); | ||
layer.layer(mapped.inner) | ||
Route::new(layer.layer(mapped.inner)) | ||
} | ||
} | ||
|
||
|
@@ -282,11 +288,12 @@ pub struct FailOnMissingOperation; | |
impl<P, Op, Exts, B, Pl> Upgradable<P, Op, Exts, B, Pl> for FailOnMissingOperation | ||
where | ||
InternalFailureException: IntoResponse<P>, | ||
P: Send + 'static, | ||
82marbag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
type Service = MissingFailure<P>; | ||
|
||
fn upgrade(self, _plugin: &Pl) -> Self::Service { | ||
MissingFailure { _protocol: PhantomData } | ||
fn upgrade(self, _plugin: &Pl) -> Route<B> { | ||
Route::new(MissingFailure { _protocol: PhantomData }) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Formatter did this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this because Intellij formats TODO lines if they are prefixed with a space, but can remove