mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 04:47:39 +03:00
PipelineCall is static (#215)
* PipelineCall is static * Fix static lifetimes req
This commit is contained in:
parent
1fd6311a5d
commit
4380b3a155
13 changed files with 43 additions and 51 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changes
|
||||
|
||||
## [1.2.1] - 2023-06-23
|
||||
|
||||
* Make `PipelineCall` static
|
||||
|
||||
## [1.2.0] - 2023-06-22
|
||||
|
||||
* Rename Container to Pipeline
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-service"
|
||||
version = "1.2.0"
|
||||
version = "1.2.1"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
description = "ntex service"
|
||||
keywords = ["network", "framework", "async", "futures"]
|
||||
|
|
|
@ -85,7 +85,7 @@ mod tests {
|
|||
|
||||
let pipe = Pipeline::new(chain(srv).and_then(on_shutdown).clone());
|
||||
|
||||
let res = pipe.call(()).await;
|
||||
let res = pipe.service_call(()).await;
|
||||
assert_eq!(lazy(|cx| pipe.poll_ready(cx)).await, Poll::Ready(Ok(())));
|
||||
assert!(res.is_ok());
|
||||
assert_eq!(res.unwrap(), "pipe");
|
||||
|
|
|
@ -69,9 +69,10 @@ impl<S> Pipeline<S> {
|
|||
/// Call service and create future object that resolves to service result.
|
||||
///
|
||||
/// Note, this call does not check service readiness.
|
||||
pub fn call<R>(&self, req: R) -> PipelineCall<'_, S, R>
|
||||
pub fn call<R>(&self, req: R) -> PipelineCall<S, R>
|
||||
where
|
||||
S: Service<R>,
|
||||
S: Service<R> + 'static,
|
||||
R: 'static,
|
||||
{
|
||||
let pipeline = self.clone();
|
||||
let svc_call = pipeline.svc.call(req, ServiceCtx::new(&pipeline.waiters));
|
||||
|
@ -111,41 +112,19 @@ impl<S> Clone for Pipeline<S> {
|
|||
|
||||
pin_project_lite::pin_project! {
|
||||
#[must_use = "futures do nothing unless polled"]
|
||||
pub struct PipelineCall<'f, S, R>
|
||||
pub struct PipelineCall<S, R>
|
||||
where
|
||||
S: Service<R>,
|
||||
S: 'f,
|
||||
R: 'f,
|
||||
S: 'static,
|
||||
R: 'static,
|
||||
{
|
||||
#[pin]
|
||||
fut: S::Future<'f>,
|
||||
fut: S::Future<'static>,
|
||||
pipeline: Pipeline<S>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'f, S, R> PipelineCall<'f, S, R>
|
||||
where
|
||||
S: Service<R> + 'f,
|
||||
R: 'f,
|
||||
{
|
||||
#[inline]
|
||||
/// Convert future object to static version.
|
||||
///
|
||||
/// Returned future is suitable for spawning into a async runtime.
|
||||
/// Note, this call does not check service readiness.
|
||||
pub fn into_static(self) -> PipelineCall<'static, S, R> {
|
||||
let svc_call = self.fut;
|
||||
let pipeline = self.pipeline;
|
||||
|
||||
// SAFETY: `svc_call` has same lifetime same as lifetime of `pipeline.svc`
|
||||
// Pipeline::svc is heap allocated(Rc<S>), we keep it alive until
|
||||
// `svc_call` get resolved to result
|
||||
let fut = unsafe { std::mem::transmute(svc_call) };
|
||||
PipelineCall { fut, pipeline }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'f, S, R> future::Future for PipelineCall<'f, S, R>
|
||||
impl<S, R> future::Future for PipelineCall<S, R>
|
||||
where
|
||||
S: Service<R>,
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue