From 996f2afdb7bf9b0a5757aa864458fddee9f1f72f Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 14 Aug 2023 16:23:10 +0600 Subject: [PATCH] Use Pipeline instead of ApplyService --- ntex-service/CHANGES.md | 4 ++++ ntex-service/Cargo.toml | 2 +- ntex-service/src/apply.rs | 43 ++++++++++++--------------------------- ntex-service/src/chain.rs | 6 +++--- ntex-service/src/lib.rs | 5 ++++- ntex/Cargo.toml | 2 +- 6 files changed, 26 insertions(+), 36 deletions(-) diff --git a/ntex-service/CHANGES.md b/ntex-service/CHANGES.md index 5ef8da472..edb633c66 100644 --- a/ntex-service/CHANGES.md +++ b/ntex-service/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [1.2.5] - 2023-08-14 + +* Use Pipeline instead of ApplyService + ## [1.2.4] - 2023-08-12 * Forward readiness check for Apply service diff --git a/ntex-service/Cargo.toml b/ntex-service/Cargo.toml index 0c303df65..9aabfb09f 100644 --- a/ntex-service/Cargo.toml +++ b/ntex-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-service" -version = "1.2.4" +version = "1.2.5" authors = ["ntex contributors "] description = "ntex service" keywords = ["network", "framework", "async", "futures"] diff --git a/ntex-service/src/apply.rs b/ntex-service/src/apply.rs index 3f498ac23..388f601da 100644 --- a/ntex-service/src/apply.rs +++ b/ntex-service/src/apply.rs @@ -1,7 +1,7 @@ #![allow(clippy::type_complexity)] use std::{future::Future, marker, pin::Pin, task, task::Poll}; -use super::ctx::{ServiceCall, ServiceCtx}; +use super::ctx::ServiceCtx; use super::{IntoService, IntoServiceFactory, Pipeline, Service, ServiceFactory}; /// Apply transform function to a service. @@ -11,7 +11,7 @@ pub fn apply_fn( ) -> Apply where T: Service, - F: Fn(In, ApplyService) -> R, + F: Fn(In, Pipeline) -> R, R: Future>, U: IntoService, { @@ -25,7 +25,7 @@ pub fn apply_fn_factory( ) -> ApplyFactory where T: ServiceFactory, - F: Fn(In, ApplyService) -> R + Clone, + F: Fn(In, Pipeline) -> R + Clone, R: Future>, U: IntoServiceFactory, { @@ -42,24 +42,10 @@ where r: marker::PhantomData (In, Out, R)>, } -pub struct ApplyService { - service: Pipeline, -} - -impl ApplyService { - /// Check readiness and call enclosed service. - pub fn call(&self, req: R) -> ServiceCall<'_, S, R> - where - S: Service, - { - self.service.call(req) - } -} - impl Apply where T: Service, - F: Fn(In, ApplyService) -> R, + F: Fn(In, Pipeline) -> R, R: Future>, { pub(crate) fn new(service: T, f: F) -> Self { @@ -74,7 +60,7 @@ where impl Clone for Apply where T: Service + Clone, - F: Fn(In, ApplyService) -> R + Clone, + F: Fn(In, Pipeline) -> R + Clone, R: Future>, { fn clone(&self) -> Self { @@ -89,7 +75,7 @@ where impl Service for Apply where T: Service, - F: Fn(In, ApplyService) -> R, + F: Fn(In, Pipeline) -> R, R: Future>, { type Response = Out; @@ -101,10 +87,7 @@ where #[inline] fn call<'a>(&'a self, req: In, _: ServiceCtx<'a, Self>) -> Self::Future<'a> { - let svc = ApplyService { - service: self.service.clone(), - }; - (self.f)(req, svc) + (self.f)(req, self.service.clone()) } } @@ -112,7 +95,7 @@ where pub struct ApplyFactory where T: ServiceFactory, - F: Fn(In, ApplyService) -> R + Clone, + F: Fn(In, Pipeline) -> R + Clone, R: Future>, { service: T, @@ -123,7 +106,7 @@ where impl ApplyFactory where T: ServiceFactory, - F: Fn(In, ApplyService) -> R + Clone, + F: Fn(In, Pipeline) -> R + Clone, R: Future>, { /// Create new `ApplyNewService` new service instance @@ -140,7 +123,7 @@ impl Clone for ApplyFactory where T: ServiceFactory + Clone, - F: Fn(In, ApplyService) -> R + Clone, + F: Fn(In, Pipeline) -> R + Clone, R: Future>, { fn clone(&self) -> Self { @@ -156,7 +139,7 @@ impl ServiceFactory for ApplyFactory where T: ServiceFactory, - F: Fn(In, ApplyService) -> R + Clone, + F: Fn(In, Pipeline) -> R + Clone, for<'r> R: Future> + 'r, { type Response = Out; @@ -181,7 +164,7 @@ pin_project_lite::pin_project! { where T: ServiceFactory, T: 'f, - F: Fn(In, ApplyService) -> R, + F: Fn(In, Pipeline) -> R, T::Service: 'f, R: Future>, Cfg: 'f, @@ -197,7 +180,7 @@ impl<'f, T, Req, Cfg, F, R, In, Out, Err> Future for ApplyFactoryResponse<'f, T, Req, Cfg, F, R, In, Out, Err> where T: ServiceFactory, - F: Fn(In, ApplyService) -> R, + F: Fn(In, Pipeline) -> R, R: Future>, { type Output = Result, T::InitError>; diff --git a/ntex-service/src/chain.rs b/ntex-service/src/chain.rs index fa73556a1..3767715c6 100644 --- a/ntex-service/src/chain.rs +++ b/ntex-service/src/chain.rs @@ -2,7 +2,7 @@ use std::{future::Future, marker::PhantomData}; use crate::and_then::{AndThen, AndThenFactory}; -use crate::apply::{Apply, ApplyFactory, ApplyService}; +use crate::apply::{Apply, ApplyFactory}; use crate::ctx::{ServiceCall, ServiceCtx}; use crate::map::{Map, MapFactory}; use crate::map_err::{MapErr, MapErrFactory}; @@ -128,7 +128,7 @@ impl, Req> ServiceChain { f: F, ) -> ServiceChain, In> where - F: Fn(In, ApplyService) -> R, + F: Fn(In, Pipeline) -> R, R: Future>, Svc: Service, { @@ -214,7 +214,7 @@ impl, Req, C> ServiceChainFactory { f: F, ) -> ServiceChainFactory, In, C> where - F: Fn(In, ApplyService) -> R + Clone, + F: Fn(In, Pipeline) -> R + Clone, R: Future>, T: ServiceFactory, { diff --git a/ntex-service/src/lib.rs b/ntex-service/src/lib.rs index a1f3e19b6..a02e364c6 100644 --- a/ntex-service/src/lib.rs +++ b/ntex-service/src/lib.rs @@ -389,7 +389,7 @@ where pub mod dev { pub use crate::and_then::{AndThen, AndThenFactory}; - pub use crate::apply::{Apply, ApplyFactory, ApplyService}; + pub use crate::apply::{Apply, ApplyFactory}; pub use crate::chain::{ServiceChain, ServiceChainFactory}; pub use crate::fn_service::{ FnService, FnServiceConfig, FnServiceFactory, FnServiceNoConfig, @@ -402,4 +402,7 @@ pub mod dev { pub use crate::middleware::ApplyMiddleware; pub use crate::pipeline::CreatePipeline; pub use crate::then::{Then, ThenFactory}; + + #[doc(hidden)] + pub type ApplyService = crate::Pipeline; } diff --git a/ntex/Cargo.toml b/ntex/Cargo.toml index b681aead8..f4a213a90 100644 --- a/ntex/Cargo.toml +++ b/ntex/Cargo.toml @@ -52,7 +52,7 @@ ntex-codec = "0.6.2" ntex-connect = "0.3.0" ntex-http = "0.1.9" ntex-router = "0.5.1" -ntex-service = "1.2.3" +ntex-service = "1.2.5" ntex-macros = "0.1.3" ntex-util = "0.3.0" ntex-bytes = "0.1.19"