mirror of
https://github.com/fafhrd91/actix-net
synced 2025-06-26 19:47:43 +02:00
cleanup Unpin constraint; simplify Framed impl
This commit is contained in:
@ -23,6 +23,7 @@ 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"
|
||||
|
@ -83,8 +83,6 @@ 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;
|
||||
@ -114,39 +112,31 @@ impl<A: Clone, B: Clone> Clone for Either<A, B> {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[pin_project::pin_project]
|
||||
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.get_mut();
|
||||
let this = self.project();
|
||||
|
||||
if this.left.is_none() {
|
||||
this.left = Some(ready!(Pin::new(&mut this.left_fut).poll(cx))?);
|
||||
*this.left = Some(ready!(this.left_fut.poll(cx))?);
|
||||
}
|
||||
if this.right.is_none() {
|
||||
this.right = Some(ready!(Pin::new(&mut this.right_fut).poll(cx))?);
|
||||
*this.right = Some(ready!(this.right_fut.poll(cx))?);
|
||||
}
|
||||
|
||||
if this.left.is_some() && this.right.is_some() {
|
||||
|
@ -77,13 +77,14 @@ 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::pin_project]
|
||||
pub struct FramedTransport<S, T, U>
|
||||
where
|
||||
S: Service<Request = Request<U>, Response = Response<U>>,
|
||||
S::Error: 'static,
|
||||
S::Future: 'static,
|
||||
T: AsyncRead + AsyncWrite + Unpin,
|
||||
U: Encoder + Decoder + Unpin,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
U: Encoder + Decoder,
|
||||
<U as Encoder>::Item: 'static,
|
||||
<U as Encoder>::Error: std::fmt::Debug,
|
||||
{
|
||||
@ -109,11 +110,11 @@ struct FramedTransportInner<I, E> {
|
||||
|
||||
impl<S, T, U> FramedTransport<S, T, U>
|
||||
where
|
||||
S: Service<Request = Request<U>, Response = Response<U>> + Unpin,
|
||||
S: Service<Request = Request<U>, Response = Response<U>>,
|
||||
S::Error: 'static,
|
||||
S::Future: 'static,
|
||||
T: AsyncRead + AsyncWrite + Unpin,
|
||||
U: Decoder + Encoder + Unpin,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
U: Decoder + Encoder,
|
||||
<U as Encoder>::Item: 'static,
|
||||
<U as Encoder>::Error: std::fmt::Debug,
|
||||
{
|
||||
@ -165,28 +166,28 @@ where
|
||||
|
||||
impl<S, T, U> Future for FramedTransport<S, T, U>
|
||||
where
|
||||
S: Service<Request = Request<U>, Response = Response<U>> + Unpin,
|
||||
S::Error: Unpin + 'static,
|
||||
S: Service<Request = Request<U>, Response = Response<U>>,
|
||||
S::Error: 'static,
|
||||
S::Future: 'static,
|
||||
T: AsyncRead + AsyncWrite + Unpin,
|
||||
U: Decoder + Encoder + Unpin,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
U: Decoder + Encoder,
|
||||
<U as Encoder>::Item: 'static,
|
||||
<U as Encoder>::Error: Unpin + std::fmt::Debug,
|
||||
<U as Decoder>::Error: Unpin + std::fmt::Debug,
|
||||
<U as Encoder>::Error: std::fmt::Debug,
|
||||
<U as Decoder>::Error: 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.get_mut();
|
||||
let this = self.project();
|
||||
poll(
|
||||
cx,
|
||||
&mut this.service,
|
||||
&mut this.state,
|
||||
&mut this.framed,
|
||||
&mut this.rx,
|
||||
&mut this.inner,
|
||||
this.service,
|
||||
this.state,
|
||||
this.framed,
|
||||
this.rx,
|
||||
this.inner,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -203,8 +204,8 @@ where
|
||||
S: Service<Request = Request<U>, Response = Response<U>>,
|
||||
S::Error: 'static,
|
||||
S::Future: 'static,
|
||||
T: AsyncRead + AsyncWrite + Unpin,
|
||||
U: Decoder + Encoder + Unpin,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
U: Decoder + Encoder,
|
||||
<U as Encoder>::Item: 'static,
|
||||
<U as Encoder>::Error: std::fmt::Debug,
|
||||
{
|
||||
@ -257,8 +258,8 @@ where
|
||||
S: Service<Request = Request<U>, Response = Response<U>>,
|
||||
S::Error: 'static,
|
||||
S::Future: 'static,
|
||||
T: AsyncRead + AsyncWrite + Unpin,
|
||||
U: Decoder + Encoder + Unpin,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
U: Decoder + Encoder,
|
||||
<U as Encoder>::Item: 'static,
|
||||
<U as Encoder>::Error: std::fmt::Debug,
|
||||
{
|
||||
@ -309,8 +310,8 @@ where
|
||||
S: Service<Request = Request<U>, Response = Response<U>>,
|
||||
S::Error: 'static,
|
||||
S::Future: 'static,
|
||||
T: AsyncRead + AsyncWrite + Unpin,
|
||||
U: Decoder + Encoder + Unpin,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
U: Decoder + Encoder,
|
||||
<U as Encoder>::Item: 'static,
|
||||
<U as Encoder>::Error: std::fmt::Debug,
|
||||
{
|
||||
|
@ -31,7 +31,6 @@ impl Default for InFlight {
|
||||
impl<S> Transform<S> for InFlight
|
||||
where
|
||||
S: Service,
|
||||
S::Future: Unpin,
|
||||
{
|
||||
type Request = S::Request;
|
||||
type Response = S::Response;
|
||||
@ -68,7 +67,6 @@ where
|
||||
impl<T> Service for InFlightService<T>
|
||||
where
|
||||
T: Service,
|
||||
T::Future: Unpin,
|
||||
{
|
||||
type Request = T::Request;
|
||||
type Response = T::Response;
|
||||
@ -95,19 +93,18 @@ where
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[pin_project::pin_project]
|
||||
pub struct InFlightServiceResponse<T: Service> {
|
||||
#[pin]
|
||||
fut: T::Future,
|
||||
_guard: CounterGuard,
|
||||
}
|
||||
|
||||
impl<T: Service> Future for InFlightServiceResponse<T>
|
||||
where
|
||||
T::Future: Unpin,
|
||||
{
|
||||
impl<T: Service> Future for InFlightServiceResponse<T> {
|
||||
type Output = Result<T::Response, T::Error>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||
Pin::new(&mut self.get_mut().fut).poll(cx)
|
||||
self.project().fut.poll(cx)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,6 @@ 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,7 +125,6 @@ where
|
||||
impl<S> Service for TimeoutService<S>
|
||||
where
|
||||
S: Service,
|
||||
S::Future: Unpin,
|
||||
{
|
||||
type Request = S::Request;
|
||||
type Response = S::Response;
|
||||
@ -146,8 +144,10 @@ where
|
||||
}
|
||||
|
||||
/// `TimeoutService` response future
|
||||
#[pin_project::pin_project]
|
||||
#[derive(Debug)]
|
||||
pub struct TimeoutServiceResponse<T: Service> {
|
||||
#[pin]
|
||||
fut: T::Future,
|
||||
sleep: Delay,
|
||||
}
|
||||
@ -155,15 +155,14 @@ 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 this = self.get_mut();
|
||||
let mut this = self.project();
|
||||
|
||||
// First, try polling the future
|
||||
match Pin::new(&mut this.fut).poll(cx) {
|
||||
match 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 => {}
|
||||
|
Reference in New Issue
Block a user