1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-26 19:47:43 +02:00

remove pin-project; update Unpin consrtaint

This commit is contained in:
Nikolay Kim
2019-11-18 18:28:54 +06:00
parent 7404d82a9b
commit 1354946460
22 changed files with 225 additions and 161 deletions

View File

@ -23,7 +23,6 @@ actix-codec = "0.2.0-alpha.1"
bytes = "0.4"
either = "1.5.2"
futures = "0.3.1"
pin-project = "0.4.5"
tokio-timer = "0.3.0-alpha.6"
tokio-executor = { version="=0.2.0-alpha.6", features=["current-thread"] }
log = "0.4"

View File

@ -4,7 +4,6 @@ use std::task::{Context, Poll};
use actix_service::{Service, ServiceFactory};
use futures::{future, ready, Future};
use pin_project::pin_project;
/// Combine two different service types into a single type.
///
@ -84,6 +83,8 @@ where
Error = A::Error,
InitError = A::InitError,
>,
A::Future: Unpin,
B::Future: Unpin,
{
type Request = either::Either<A::Request, B::Request>;
type Response = A::Response;
@ -112,32 +113,40 @@ impl<A: Clone, B: Clone> Clone for Either<A, B> {
}
}
#[pin_project]
#[doc(hidden)]
pub struct EitherNewService<A: ServiceFactory, B: ServiceFactory> {
left: Option<A::Service>,
right: Option<B::Service>,
#[pin]
left_fut: A::Future,
#[pin]
right_fut: B::Future,
}
impl<A, B> Unpin for EitherNewService<A, B>
where
A: ServiceFactory,
B: ServiceFactory<Response = A::Response, Error = A::Error, InitError = A::InitError>,
A::Future: Unpin,
B::Future: Unpin,
{
}
impl<A, B> Future for EitherNewService<A, B>
where
A: ServiceFactory,
B: ServiceFactory<Response = A::Response, Error = A::Error, InitError = A::InitError>,
A::Future: Unpin,
B::Future: Unpin,
{
type Output = Result<EitherService<A::Service, B::Service>, A::InitError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let this = self.project();
let this = self.get_mut();
if this.left.is_none() {
*this.left = Some(ready!(this.left_fut.poll(cx))?);
this.left = Some(ready!(Pin::new(&mut this.left_fut).poll(cx))?);
}
if this.right.is_none() {
*this.right = Some(ready!(this.right_fut.poll(cx))?);
this.right = Some(ready!(Pin::new(&mut this.right_fut).poll(cx))?);
}
if this.left.is_some() && this.right.is_some() {

View File

@ -10,7 +10,6 @@ use actix_service::{IntoService, Service};
use futures::future::{ready, FutureExt};
use futures::{Future, Sink, Stream};
use log::debug;
use pin_project::pin_project;
use crate::cell::Cell;
use crate::mpsc;
@ -78,7 +77,6 @@ type Inner<S: Service, U> = Cell<FramedTransportInner<<U as Encoder>::Item, S::E
/// FramedTransport - is a future that reads frames from Framed object
/// and pass then to the service.
#[pin_project]
pub struct FramedTransport<S, T, U>
where
S: Service<Request = Request<U>, Response = Response<U>>,
@ -111,7 +109,7 @@ struct FramedTransportInner<I, E> {
impl<S, T, U> FramedTransport<S, T, U>
where
S: Service<Request = Request<U>, Response = Response<U>>,
S: Service<Request = Request<U>, Response = Response<U>> + Unpin,
S::Error: 'static,
S::Future: 'static,
T: AsyncRead + AsyncWrite + Unpin,
@ -167,27 +165,28 @@ where
impl<S, T, U> Future for FramedTransport<S, T, U>
where
S: Service<Request = Request<U>, Response = Response<U>>,
S::Error: 'static,
S: Service<Request = Request<U>, Response = Response<U>> + Unpin,
S::Error: Unpin + 'static,
S::Future: 'static,
T: AsyncRead + AsyncWrite + Unpin,
U: Decoder + Encoder + Unpin,
<U as Encoder>::Item: 'static,
<U as Encoder>::Error: std::fmt::Debug,
<U as Encoder>::Error: Unpin + std::fmt::Debug,
<U as Decoder>::Error: Unpin + std::fmt::Debug,
{
type Output = Result<(), FramedTransportError<S::Error, U>>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
self.inner.get_ref().task.register(cx.waker());
let this = self.project();
let this = self.get_mut();
poll(
cx,
this.service,
this.state,
this.framed,
this.rx,
this.inner,
&mut this.service,
&mut this.state,
&mut this.framed,
&mut this.rx,
&mut this.inner,
)
}
}

View File

@ -5,7 +5,6 @@ use std::task::{Context, Poll};
use actix_service::{IntoService, Service, Transform};
use futures::future::{ok, Ready};
use pin_project::pin_project;
use super::counter::{Counter, CounterGuard};
@ -29,7 +28,11 @@ impl Default for InFlight {
}
}
impl<S: Service> Transform<S> for InFlight {
impl<S> Transform<S> for InFlight
where
S: Service,
S::Future: Unpin,
{
type Request = S::Request;
type Response = S::Response;
type Error = S::Error;
@ -65,6 +68,7 @@ where
impl<T> Service for InFlightService<T>
where
T: Service,
T::Future: Unpin,
{
type Request = T::Request;
type Response = T::Response;
@ -90,19 +94,20 @@ where
}
}
#[pin_project]
#[doc(hidden)]
pub struct InFlightServiceResponse<T: Service> {
#[pin]
fut: T::Future,
_guard: CounterGuard,
}
impl<T: Service> Future for InFlightServiceResponse<T> {
impl<T: Service> Future for InFlightServiceResponse<T>
where
T::Future: Unpin,
{
type Output = Result<T::Response, T::Error>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
self.project().fut.poll(cx)
Pin::new(&mut self.get_mut().fut).poll(cx)
}
}

View File

@ -10,7 +10,6 @@ use std::{fmt, time};
use actix_service::{IntoService, Service, Transform};
use futures::future::{ok, Ready};
use pin_project::pin_project;
use tokio_timer::{clock, delay, Delay};
/// Applies a timeout to requests.
@ -85,6 +84,7 @@ impl<E> Clone for Timeout<E> {
impl<S, E> Transform<S> for Timeout<E>
where
S: Service,
S::Future: Unpin,
{
type Request = S::Request;
type Response = S::Response;
@ -126,6 +126,7 @@ where
impl<S> Service for TimeoutService<S>
where
S: Service,
S::Future: Unpin,
{
type Request = S::Request;
type Response = S::Response;
@ -145,10 +146,8 @@ where
}
/// `TimeoutService` response future
#[pin_project]
#[derive(Debug)]
pub struct TimeoutServiceResponse<T: Service> {
#[pin]
fut: T::Future,
sleep: Delay,
}
@ -156,14 +155,15 @@ pub struct TimeoutServiceResponse<T: Service> {
impl<T> Future for TimeoutServiceResponse<T>
where
T: Service,
T::Future: Unpin,
{
type Output = Result<T::Response, TimeoutError<T::Error>>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.project();
let this = self.get_mut();
// First, try polling the future
match this.fut.poll(cx) {
match Pin::new(&mut this.fut).poll(cx) {
Poll::Ready(Ok(v)) => return Poll::Ready(Ok(v)),
Poll::Ready(Err(e)) => return Poll::Ready(Err(TimeoutError::Service(e))),
Poll::Pending => {}