add type bound to App::wrap and wrap_fn

This commit is contained in:
fakeshadow 2021-12-07 20:00:14 +08:00
parent 2cbfae9685
commit ac9d5c32f7
1 changed files with 21 additions and 7 deletions

View File

@ -51,10 +51,7 @@ impl App<AppEntry> {
}
}
impl<T> App<T>
where
T: ServiceFactory<ServiceRequest, Error = Error, Config = (), InitError = ()>,
{
impl<T> App<T> {
/// Set application (root level) data.
///
/// Application data stored with `App::app_data()` method is available through the
@ -353,7 +350,7 @@ where
/// .route("/index.html", web::get().to(index));
/// }
/// ```
pub fn wrap<M, B1>(
pub fn wrap<M, B, B1>(
self,
mw: M,
) -> App<
@ -366,6 +363,14 @@ where
>,
>
where
T: ServiceFactory<
ServiceRequest,
Response = ServiceResponse<B>,
Error = Error,
Config = (),
InitError = (),
>,
B: MessageBody,
M: Transform<
T::Service,
ServiceRequest,
@ -373,6 +378,7 @@ where
Error = Error,
InitError = (),
>,
B1: MessageBody,
{
App {
endpoint: apply(mw, self.endpoint),
@ -416,7 +422,7 @@ where
/// .route("/index.html", web::get().to(index));
/// }
/// ```
pub fn wrap_fn<B1, F, R>(
pub fn wrap_fn<F, R, B, B1>(
self,
mw: F,
) -> App<
@ -429,9 +435,17 @@ where
>,
>
where
B1: MessageBody,
T: ServiceFactory<
ServiceRequest,
Response = ServiceResponse<B>,
Error = Error,
Config = (),
InitError = (),
>,
B: MessageBody,
F: Fn(ServiceRequest, &T::Service) -> R + Clone,
R: Future<Output = Result<ServiceResponse<B1>, Error>>,
B1: MessageBody,
{
App {
endpoint: apply_fn_factory(self.endpoint, mw),