mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 21:07:39 +03:00
Remove boxed rc service
This commit is contained in:
parent
e450ac80b8
commit
274488bd84
2 changed files with 9 additions and 127 deletions
|
@ -6,6 +6,8 @@
|
|||
|
||||
* Introduce service sharable readiness
|
||||
|
||||
* Remove boxed rc service
|
||||
|
||||
## [1.0.2] - 2023-04-14
|
||||
|
||||
* Remove Rc<S> where S: Service as it brakes readiness check validity
|
||||
|
|
|
@ -5,6 +5,12 @@ use crate::Ctx;
|
|||
|
||||
pub type BoxFuture<'a, I, E> = Pin<Box<dyn Future<Output = Result<I, E>> + 'a>>;
|
||||
|
||||
pub struct BoxService<Req, Res, Err>(Box<dyn ServiceObj<Req, Response = Res, Error = Err>>);
|
||||
|
||||
pub struct BoxServiceFactory<Cfg, Req, Res, Err, InitErr>(
|
||||
Box<dyn ServiceFactoryObj<Req, Cfg, Response = Res, Error = Err, InitError = InitErr>>,
|
||||
);
|
||||
|
||||
/// Create boxed service factory
|
||||
pub fn factory<F, R, C>(
|
||||
factory: F,
|
||||
|
@ -18,19 +24,6 @@ where
|
|||
BoxServiceFactory(Box::new(factory))
|
||||
}
|
||||
|
||||
/// Create rc boxed service factory
|
||||
pub fn rcfactory<F, R, C>(
|
||||
factory: F,
|
||||
) -> RcServiceFactory<C, R, F::Response, F::Error, F::InitError>
|
||||
where
|
||||
R: 'static,
|
||||
C: 'static,
|
||||
F: crate::ServiceFactory<R, C> + 'static,
|
||||
F::Service: 'static,
|
||||
{
|
||||
RcServiceFactory(Rc::new(factory))
|
||||
}
|
||||
|
||||
/// Create boxed service
|
||||
pub fn service<S, R>(service: S) -> BoxService<R, S::Response, S::Error>
|
||||
where
|
||||
|
@ -40,16 +33,7 @@ where
|
|||
BoxService(Box::new(service))
|
||||
}
|
||||
|
||||
/// Create rc service
|
||||
pub fn rcservice<S, R>(service: S) -> RcService<R, S::Response, S::Error>
|
||||
where
|
||||
R: 'static,
|
||||
S: crate::Service<R> + 'static,
|
||||
{
|
||||
RcService(Rc::new(service))
|
||||
}
|
||||
|
||||
pub trait ServiceObj<Req> {
|
||||
trait ServiceObj<Req> {
|
||||
type Response;
|
||||
type Error;
|
||||
|
||||
|
@ -107,19 +91,6 @@ trait ServiceFactoryObj<Req, Cfg> {
|
|||
Cfg: 'a;
|
||||
}
|
||||
|
||||
trait ServiceFactoryRcObj<Req, Cfg> {
|
||||
type Response;
|
||||
type Error;
|
||||
type InitError;
|
||||
|
||||
fn create<'a>(
|
||||
&'a self,
|
||||
cfg: Cfg,
|
||||
) -> BoxFuture<'a, RcService<Req, Self::Response, Self::Error>, Self::InitError>
|
||||
where
|
||||
Cfg: 'a;
|
||||
}
|
||||
|
||||
impl<F, Req, Cfg> ServiceFactoryObj<Req, Cfg> for F
|
||||
where
|
||||
Cfg: 'static,
|
||||
|
@ -144,32 +115,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<F, Req, Cfg> ServiceFactoryRcObj<Req, Cfg> for F
|
||||
where
|
||||
Cfg: 'static,
|
||||
Req: 'static,
|
||||
F: crate::ServiceFactory<Req, Cfg>,
|
||||
F::Service: 'static,
|
||||
{
|
||||
type Response = F::Response;
|
||||
type Error = F::Error;
|
||||
type InitError = F::InitError;
|
||||
|
||||
#[inline]
|
||||
fn create<'a>(
|
||||
&'a self,
|
||||
cfg: Cfg,
|
||||
) -> BoxFuture<'a, RcService<Req, Self::Response, Self::Error>, Self::InitError>
|
||||
where
|
||||
Cfg: 'a,
|
||||
{
|
||||
let fut = crate::ServiceFactory::create(self, cfg);
|
||||
Box::pin(async move { fut.await.map(rcservice) })
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BoxService<Req, Res, Err>(Box<dyn ServiceObj<Req, Response = Res, Error = Err>>);
|
||||
|
||||
impl<Req, Res, Err> crate::Service<Req> for BoxService<Req, Res, Err>
|
||||
where
|
||||
Req: 'static,
|
||||
|
@ -195,43 +140,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub struct RcService<Req, Res, Err>(Rc<dyn ServiceObj<Req, Response = Res, Error = Err>>);
|
||||
|
||||
impl<Req, Res, Err> Clone for RcService<Req, Res, Err> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<Req, Res, Err> crate::Service<Req> for RcService<Req, Res, Err>
|
||||
where
|
||||
Req: 'static,
|
||||
{
|
||||
type Response = Res;
|
||||
type Error = Err;
|
||||
type Future<'f> = BoxFuture<'f, Res, Err> where Self: 'f, Req: 'f;
|
||||
|
||||
#[inline]
|
||||
fn poll_ready(&self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.0.poll_ready(ctx)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn poll_shutdown(&self, cx: &mut Context<'_>) -> Poll<()> {
|
||||
self.0.poll_shutdown(cx)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn call<'a>(&'a self, req: Req, ctx: Ctx<'a, Self>) -> Self::Future<'a> {
|
||||
let (index, waiters) = ctx.into_inner();
|
||||
self.0.call(req, index, waiters)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BoxServiceFactory<Cfg, Req, Res, Err, InitErr>(
|
||||
Box<dyn ServiceFactoryObj<Req, Cfg, Response = Res, Error = Err, InitError = InitErr>>,
|
||||
);
|
||||
|
||||
impl<C, Req, Res, Err, InitErr> crate::ServiceFactory<Req, C>
|
||||
for BoxServiceFactory<C, Req, Res, Err, InitErr>
|
||||
where
|
||||
|
@ -249,31 +157,3 @@ where
|
|||
self.0.create(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RcServiceFactory<Cfg, Req, Res, Err, InitErr>(
|
||||
Rc<dyn ServiceFactoryRcObj<Req, Cfg, Response = Res, Error = Err, InitError = InitErr>>,
|
||||
);
|
||||
|
||||
impl<C, Req, Res, Err, InitErr> Clone for RcServiceFactory<C, Req, Res, Err, InitErr> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, Req, Res, Err, InitErr> crate::ServiceFactory<Req, C>
|
||||
for RcServiceFactory<C, Req, Res, Err, InitErr>
|
||||
where
|
||||
Req: 'static,
|
||||
{
|
||||
type Response = Res;
|
||||
type Error = Err;
|
||||
|
||||
type Service = RcService<Req, Res, Err>;
|
||||
type InitError = InitErr;
|
||||
type Future<'f> = BoxFuture<'f, Self::Service, InitErr> where Self: 'f, C: 'f;
|
||||
|
||||
#[inline]
|
||||
fn create(&self, cfg: C) -> Self::Future<'_> {
|
||||
self.0.create(cfg)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue