Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove pin-project from actix-web. #2471

Merged
merged 3 commits into from Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -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"] }
Expand Down
10 changes: 6 additions & 4 deletions src/middleware/compat.rs
Expand Up @@ -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};

Expand Down Expand Up @@ -89,10 +90,11 @@ where
}
}

#[pin_project::pin_project]
pub struct CompatMiddlewareFuture<Fut> {
#[pin]
fut: Fut,
pin_project! {
pub struct CompatMiddlewareFuture<Fut> {
#[pin]
fut: Fut,
}
}

impl<Fut, T, E> Future for CompatMiddlewareFuture<Fut>
Expand Down
21 changes: 11 additions & 10 deletions src/middleware/compress.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -162,15 +162,16 @@ where
}
}

#[pin_project]
pub struct CompressResponse<S, B>
where
S: Service<ServiceRequest>,
{
#[pin]
fut: S::Future,
encoding: ContentEncoding,
_phantom: PhantomData<B>,
pin_project! {
pub struct CompressResponse<S, B>
where
S: Service<ServiceRequest>,
{
#[pin]
fut: S::Future,
encoding: ContentEncoding,
_phantom: PhantomData<B>,
}
}

impl<S, B> Future for CompressResponse<S, B>
Expand Down
14 changes: 8 additions & 6 deletions src/middleware/default_headers.rs
Expand Up @@ -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},
Expand Down Expand Up @@ -153,12 +154,13 @@ where
}
}

#[pin_project::pin_project]
pub struct DefaultHeaderFuture<S: Service<ServiceRequest>, B> {
#[pin]
fut: S::Future,
inner: Rc<Inner>,
_body: PhantomData<B>,
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>
Expand Down
29 changes: 16 additions & 13 deletions src/middleware/err_handlers.rs
Expand Up @@ -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},
Expand Down Expand Up @@ -130,19 +131,21 @@ where
}
}

#[pin_project::pin_project(project = ErrorHandlersProj)]
pub enum ErrorHandlersFuture<Fut, B>
where
Fut: Future,
{
ServiceFuture {
#[pin]
fut: Fut,
handlers: Handlers<B>,
},
HandlerFuture {
fut: LocalBoxFuture<'static, Fut::Output>,
},
pin_project! {
#[project = ErrorHandlersProj]
pub enum ErrorHandlersFuture<Fut, B>
where
Fut: Future,
{
ServiceFuture {
#[pin]
fut: Fut,
handlers: Handlers<B>,
},
HandlerFuture {
fut: LocalBoxFuture<'static, Fut::Output>,
},
}
}

impl<Fut, B> Future for ErrorHandlersFuture<Fut, B>
Expand Down
73 changes: 36 additions & 37 deletions src/middleware/logger.rs
Expand Up @@ -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};

Expand Down Expand Up @@ -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 {
Expand All @@ -195,10 +196,10 @@ where
}
}

ok(LoggerMiddleware {
ready(Ok(LoggerMiddleware {
service,
inner: self.0.clone(),
})
}))
}
}

Expand Down Expand Up @@ -246,17 +247,18 @@ where
}
}

#[pin_project::pin_project]
pub struct LoggerResponse<S, B>
where
B: MessageBody,
S: Service<ServiceRequest>,
{
#[pin]
fut: S::Future,
time: OffsetDateTime,
format: Option<Format>,
_phantom: PhantomData<B>,
pin_project! {
pub struct LoggerResponse<S, B>
where
B: MessageBody,
S: Service<ServiceRequest>,
{
#[pin]
fut: S::Future,
time: OffsetDateTime,
format: Option<Format>,
_phantom: PhantomData<B>,
}
}

impl<S, B> Future for LoggerResponse<S, B>
Expand Down Expand Up @@ -296,28 +298,25 @@ where
}
}

use pin_project::{pin_project, pinned_drop};

#[pin_project(PinnedDrop)]
pub struct StreamLog<B> {
#[pin]
body: B,
format: Option<Format>,
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 {
let render = |fmt: &mut fmt::Formatter<'_>| {
for unit in &format.0 {
unit.render(fmt, self.size, self.time)?;
}
Ok(())
};
log::info!("{}", FormatDisplay(&render));
pin_project! {
pub struct StreamLog<B> {
#[pin]
body: B,
format: Option<Format>,
size: usize,
time: OffsetDateTime,
}
impl<B> PinnedDrop for StreamLog<B> {
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, this.size, this.time)?;
}
Ok(())
};
log::info!("{}", FormatDisplay(&render));
}
}
}
}
Expand Down
62 changes: 33 additions & 29 deletions src/types/either.rs
Expand Up @@ -9,6 +9,7 @@ use std::{

use bytes::Bytes;
use futures_core::ready;
use pin_project_lite::pin_project;

use crate::{
dev,
Expand Down Expand Up @@ -198,37 +199,40 @@ where
}
}

#[pin_project::pin_project]
pub struct EitherExtractFut<L, R>
where
R: FromRequest,
L: FromRequest,
{
req: HttpRequest,
#[pin]
state: EitherExtractState<L, R>,
pin_project! {
pub struct EitherExtractFut<L, R>
where
R: FromRequest,
L: FromRequest,
{
req: HttpRequest,
#[pin]
state: EitherExtractState<L, R>,
}
}

#[pin_project::pin_project(project = EitherExtractProj)]
pub enum EitherExtractState<L, R>
where
L: FromRequest,
R: FromRequest,
{
Bytes {
#[pin]
bytes: <Bytes as FromRequest>::Future,
},
Left {
#[pin]
left: L::Future,
fallback: Bytes,
},
Right {
#[pin]
right: R::Future,
left_err: Option<L::Error>,
},
pin_project! {
#[project = EitherExtractProj]
pub enum EitherExtractState<L, R>
where
L: FromRequest,
R: FromRequest,
{
Bytes {
#[pin]
bytes: <Bytes as FromRequest>::Future,
},
Left {
#[pin]
left: L::Future,
fallback: Bytes,
},
Right {
#[pin]
right: R::Future,
left_err: Option<L::Error>,
},
}
}

impl<R, RF, RE, L, LF, LE> Future for EitherExtractFut<L, R>
Expand Down