1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-29 21:11:17 +00:00

remove pin-project from actix-web. (#2471)

This commit is contained in:
fakeshadow 2021-11-30 19:16:53 +08:00 committed by GitHub
parent fc4cdf81eb
commit fa82b698b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 100 deletions

View file

@ -96,7 +96,6 @@ once_cell = "1.5"
log = "0.4"
mime = "0.3"
paste = "1"
pin-project = "1.0.0"
pin-project-lite = "0.2.7"
regex = "1.4"
serde = { version = "1.0", features = ["derive"] }

View file

@ -10,6 +10,7 @@ use std::{
use actix_http::body::{AnyBody, MessageBody};
use actix_service::{Service, Transform};
use futures_core::{future::LocalBoxFuture, ready};
use pin_project_lite::pin_project;
use crate::{error::Error, service::ServiceResponse};
@ -89,11 +90,12 @@ where
}
}
#[pin_project::pin_project]
pin_project! {
pub struct CompatMiddlewareFuture<Fut> {
#[pin]
fut: Fut,
}
}
impl<Fut, T, E> Future for CompatMiddlewareFuture<Fut>
where

View file

@ -20,7 +20,7 @@ use actix_utils::future::{ok, Either, Ready};
use bytes::Bytes;
use futures_core::ready;
use once_cell::sync::Lazy;
use pin_project::pin_project;
use pin_project_lite::pin_project;
use crate::{
dev::BodyEncoding,
@ -162,7 +162,7 @@ where
}
}
#[pin_project]
pin_project! {
pub struct CompressResponse<S, B>
where
S: Service<ServiceRequest>,
@ -172,6 +172,7 @@ where
encoding: ContentEncoding,
_phantom: PhantomData<B>,
}
}
impl<S, B> Future for CompressResponse<S, B>
where

View file

@ -11,6 +11,7 @@ use std::{
use actix_utils::future::{ready, Ready};
use futures_core::ready;
use pin_project_lite::pin_project;
use crate::{
dev::{Service, Transform},
@ -153,13 +154,14 @@ where
}
}
#[pin_project::pin_project]
pin_project! {
pub struct DefaultHeaderFuture<S: Service<ServiceRequest>, B> {
#[pin]
fut: S::Future,
inner: Rc<Inner>,
_body: PhantomData<B>,
}
}
impl<S, B> Future for DefaultHeaderFuture<S, B>
where

View file

@ -10,6 +10,7 @@ use std::{
use actix_service::{Service, Transform};
use ahash::AHashMap;
use futures_core::{future::LocalBoxFuture, ready};
use pin_project_lite::pin_project;
use crate::{
dev::{ServiceRequest, ServiceResponse},
@ -130,7 +131,8 @@ where
}
}
#[pin_project::pin_project(project = ErrorHandlersProj)]
pin_project! {
#[project = ErrorHandlersProj]
pub enum ErrorHandlersFuture<Fut, B>
where
Fut: Future,
@ -144,6 +146,7 @@ where
fut: LocalBoxFuture<'static, Fut::Output>,
},
}
}
impl<Fut, B> Future for ErrorHandlersFuture<Fut, B>
where

View file

@ -13,10 +13,11 @@ use std::{
};
use actix_service::{Service, Transform};
use actix_utils::future::{ok, Ready};
use actix_utils::future::{ready, Ready};
use bytes::Bytes;
use futures_core::ready;
use log::{debug, warn};
use pin_project_lite::pin_project;
use regex::{Regex, RegexSet};
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
@ -180,8 +181,8 @@ where
{
type Response = ServiceResponse<StreamLog<B>>;
type Error = Error;
type InitError = ();
type Transform = LoggerMiddleware<S>;
type InitError = ();
type Future = Ready<Result<Self::Transform, Self::InitError>>;
fn new_transform(&self, service: S) -> Self::Future {
@ -195,10 +196,10 @@ where
}
}
ok(LoggerMiddleware {
ready(Ok(LoggerMiddleware {
service,
inner: self.0.clone(),
})
}))
}
}
@ -246,7 +247,7 @@ where
}
}
#[pin_project::pin_project]
pin_project! {
pub struct LoggerResponse<S, B>
where
B: MessageBody,
@ -258,6 +259,7 @@ where
format: Option<Format>,
_phantom: PhantomData<B>,
}
}
impl<S, B> Future for LoggerResponse<S, B>
where
@ -296,9 +298,7 @@ where
}
}
use pin_project::{pin_project, pinned_drop};
#[pin_project(PinnedDrop)]
pin_project! {
pub struct StreamLog<B> {
#[pin]
body: B,
@ -306,14 +306,12 @@ pub struct StreamLog<B> {
size: usize,
time: OffsetDateTime,
}
#[pinned_drop]
impl<B> PinnedDrop for StreamLog<B> {
fn drop(self: Pin<&mut Self>) {
if let Some(ref format) = self.format {
fn drop(this: Pin<&mut Self>) {
if let Some(ref format) = this.format {
let render = |fmt: &mut fmt::Formatter<'_>| {
for unit in &format.0 {
unit.render(fmt, self.size, self.time)?;
unit.render(fmt, this.size, this.time)?;
}
Ok(())
};
@ -321,6 +319,7 @@ impl<B> PinnedDrop for StreamLog<B> {
}
}
}
}
impl<B> MessageBody for StreamLog<B>
where

View file

@ -9,6 +9,7 @@ use std::{
use bytes::Bytes;
use futures_core::ready;
use pin_project_lite::pin_project;
use crate::{
dev,
@ -198,7 +199,7 @@ where
}
}
#[pin_project::pin_project]
pin_project! {
pub struct EitherExtractFut<L, R>
where
R: FromRequest,
@ -208,8 +209,10 @@ where
#[pin]
state: EitherExtractState<L, R>,
}
}
#[pin_project::pin_project(project = EitherExtractProj)]
pin_project! {
#[project = EitherExtractProj]
pub enum EitherExtractState<L, R>
where
L: FromRequest,
@ -230,6 +233,7 @@ where
left_err: Option<L::Error>,
},
}
}
impl<R, RF, RE, L, LF, LE> Future for EitherExtractFut<L, R>
where