mirror of
https://github.com/actix/actix-web.git
synced 2024-11-26 03:21:08 +00:00
remove pin-project from actix-web. (#2471)
This commit is contained in:
parent
fc4cdf81eb
commit
fa82b698b7
7 changed files with 110 additions and 100 deletions
|
@ -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"] }
|
||||
|
|
|
@ -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,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>
|
||||
|
|
|
@ -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,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>
|
||||
|
|
|
@ -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,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>
|
||||
|
|
|
@ -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,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>
|
||||
|
|
|
@ -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,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>
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use std::{
|
|||
|
||||
use bytes::Bytes;
|
||||
use futures_core::ready;
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
use crate::{
|
||||
dev,
|
||||
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue