mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 22:01:50 +01:00
remove pin-project from actix-web. (#2471)
This commit is contained in:
parent
fc4cdf81eb
commit
fa82b698b7
@ -96,7 +96,6 @@ once_cell = "1.5"
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
mime = "0.3"
|
mime = "0.3"
|
||||||
paste = "1"
|
paste = "1"
|
||||||
pin-project = "1.0.0"
|
|
||||||
pin-project-lite = "0.2.7"
|
pin-project-lite = "0.2.7"
|
||||||
regex = "1.4"
|
regex = "1.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
@ -10,6 +10,7 @@ use std::{
|
|||||||
use actix_http::body::{AnyBody, MessageBody};
|
use actix_http::body::{AnyBody, MessageBody};
|
||||||
use actix_service::{Service, Transform};
|
use actix_service::{Service, Transform};
|
||||||
use futures_core::{future::LocalBoxFuture, ready};
|
use futures_core::{future::LocalBoxFuture, ready};
|
||||||
|
use pin_project_lite::pin_project;
|
||||||
|
|
||||||
use crate::{error::Error, service::ServiceResponse};
|
use crate::{error::Error, service::ServiceResponse};
|
||||||
|
|
||||||
@ -89,10 +90,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project::pin_project]
|
pin_project! {
|
||||||
pub struct CompatMiddlewareFuture<Fut> {
|
pub struct CompatMiddlewareFuture<Fut> {
|
||||||
#[pin]
|
#[pin]
|
||||||
fut: Fut,
|
fut: Fut,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Fut, T, E> Future for CompatMiddlewareFuture<Fut>
|
impl<Fut, T, E> Future for CompatMiddlewareFuture<Fut>
|
||||||
|
@ -20,7 +20,7 @@ use actix_utils::future::{ok, Either, Ready};
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use pin_project::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dev::BodyEncoding,
|
dev::BodyEncoding,
|
||||||
@ -162,15 +162,16 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project]
|
pin_project! {
|
||||||
pub struct CompressResponse<S, B>
|
pub struct CompressResponse<S, B>
|
||||||
where
|
where
|
||||||
S: Service<ServiceRequest>,
|
S: Service<ServiceRequest>,
|
||||||
{
|
{
|
||||||
#[pin]
|
#[pin]
|
||||||
fut: S::Future,
|
fut: S::Future,
|
||||||
encoding: ContentEncoding,
|
encoding: ContentEncoding,
|
||||||
_phantom: PhantomData<B>,
|
_phantom: PhantomData<B>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, B> Future for CompressResponse<S, B>
|
impl<S, B> Future for CompressResponse<S, B>
|
||||||
|
@ -11,6 +11,7 @@ use std::{
|
|||||||
|
|
||||||
use actix_utils::future::{ready, Ready};
|
use actix_utils::future::{ready, Ready};
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
|
use pin_project_lite::pin_project;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dev::{Service, Transform},
|
dev::{Service, Transform},
|
||||||
@ -153,12 +154,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project::pin_project]
|
pin_project! {
|
||||||
pub struct DefaultHeaderFuture<S: Service<ServiceRequest>, B> {
|
pub struct DefaultHeaderFuture<S: Service<ServiceRequest>, B> {
|
||||||
#[pin]
|
#[pin]
|
||||||
fut: S::Future,
|
fut: S::Future,
|
||||||
inner: Rc<Inner>,
|
inner: Rc<Inner>,
|
||||||
_body: PhantomData<B>,
|
_body: PhantomData<B>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, B> Future for DefaultHeaderFuture<S, B>
|
impl<S, B> Future for DefaultHeaderFuture<S, B>
|
||||||
|
@ -10,6 +10,7 @@ use std::{
|
|||||||
use actix_service::{Service, Transform};
|
use actix_service::{Service, Transform};
|
||||||
use ahash::AHashMap;
|
use ahash::AHashMap;
|
||||||
use futures_core::{future::LocalBoxFuture, ready};
|
use futures_core::{future::LocalBoxFuture, ready};
|
||||||
|
use pin_project_lite::pin_project;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dev::{ServiceRequest, ServiceResponse},
|
dev::{ServiceRequest, ServiceResponse},
|
||||||
@ -130,19 +131,21 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project::pin_project(project = ErrorHandlersProj)]
|
pin_project! {
|
||||||
pub enum ErrorHandlersFuture<Fut, B>
|
#[project = ErrorHandlersProj]
|
||||||
where
|
pub enum ErrorHandlersFuture<Fut, B>
|
||||||
Fut: Future,
|
where
|
||||||
{
|
Fut: Future,
|
||||||
ServiceFuture {
|
{
|
||||||
#[pin]
|
ServiceFuture {
|
||||||
fut: Fut,
|
#[pin]
|
||||||
handlers: Handlers<B>,
|
fut: Fut,
|
||||||
},
|
handlers: Handlers<B>,
|
||||||
HandlerFuture {
|
},
|
||||||
fut: LocalBoxFuture<'static, Fut::Output>,
|
HandlerFuture {
|
||||||
},
|
fut: LocalBoxFuture<'static, Fut::Output>,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Fut, B> Future for ErrorHandlersFuture<Fut, B>
|
impl<Fut, B> Future for ErrorHandlersFuture<Fut, B>
|
||||||
|
@ -13,10 +13,11 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use actix_service::{Service, Transform};
|
use actix_service::{Service, Transform};
|
||||||
use actix_utils::future::{ok, Ready};
|
use actix_utils::future::{ready, Ready};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
|
use pin_project_lite::pin_project;
|
||||||
use regex::{Regex, RegexSet};
|
use regex::{Regex, RegexSet};
|
||||||
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
|
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
|
||||||
|
|
||||||
@ -180,8 +181,8 @@ where
|
|||||||
{
|
{
|
||||||
type Response = ServiceResponse<StreamLog<B>>;
|
type Response = ServiceResponse<StreamLog<B>>;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
|
||||||
type Transform = LoggerMiddleware<S>;
|
type Transform = LoggerMiddleware<S>;
|
||||||
|
type InitError = ();
|
||||||
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
||||||
|
|
||||||
fn new_transform(&self, service: S) -> Self::Future {
|
fn new_transform(&self, service: S) -> Self::Future {
|
||||||
@ -195,10 +196,10 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ok(LoggerMiddleware {
|
ready(Ok(LoggerMiddleware {
|
||||||
service,
|
service,
|
||||||
inner: self.0.clone(),
|
inner: self.0.clone(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,17 +247,18 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project::pin_project]
|
pin_project! {
|
||||||
pub struct LoggerResponse<S, B>
|
pub struct LoggerResponse<S, B>
|
||||||
where
|
where
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
S: Service<ServiceRequest>,
|
S: Service<ServiceRequest>,
|
||||||
{
|
{
|
||||||
#[pin]
|
#[pin]
|
||||||
fut: S::Future,
|
fut: S::Future,
|
||||||
time: OffsetDateTime,
|
time: OffsetDateTime,
|
||||||
format: Option<Format>,
|
format: Option<Format>,
|
||||||
_phantom: PhantomData<B>,
|
_phantom: PhantomData<B>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, B> Future for LoggerResponse<S, B>
|
impl<S, B> Future for LoggerResponse<S, B>
|
||||||
@ -296,28 +298,25 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use pin_project::{pin_project, pinned_drop};
|
pin_project! {
|
||||||
|
pub struct StreamLog<B> {
|
||||||
#[pin_project(PinnedDrop)]
|
#[pin]
|
||||||
pub struct StreamLog<B> {
|
body: B,
|
||||||
#[pin]
|
format: Option<Format>,
|
||||||
body: B,
|
size: usize,
|
||||||
format: Option<Format>,
|
time: OffsetDateTime,
|
||||||
size: usize,
|
}
|
||||||
time: OffsetDateTime,
|
impl<B> PinnedDrop for StreamLog<B> {
|
||||||
}
|
fn drop(this: Pin<&mut Self>) {
|
||||||
|
if let Some(ref format) = this.format {
|
||||||
#[pinned_drop]
|
let render = |fmt: &mut fmt::Formatter<'_>| {
|
||||||
impl<B> PinnedDrop for StreamLog<B> {
|
for unit in &format.0 {
|
||||||
fn drop(self: Pin<&mut Self>) {
|
unit.render(fmt, this.size, this.time)?;
|
||||||
if let Some(ref format) = self.format {
|
}
|
||||||
let render = |fmt: &mut fmt::Formatter<'_>| {
|
Ok(())
|
||||||
for unit in &format.0 {
|
};
|
||||||
unit.render(fmt, self.size, self.time)?;
|
log::info!("{}", FormatDisplay(&render));
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
};
|
|
||||||
log::info!("{}", FormatDisplay(&render));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ use std::{
|
|||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
|
use pin_project_lite::pin_project;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dev,
|
dev,
|
||||||
@ -198,37 +199,40 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project::pin_project]
|
pin_project! {
|
||||||
pub struct EitherExtractFut<L, R>
|
pub struct EitherExtractFut<L, R>
|
||||||
where
|
where
|
||||||
R: FromRequest,
|
R: FromRequest,
|
||||||
L: FromRequest,
|
L: FromRequest,
|
||||||
{
|
{
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
#[pin]
|
#[pin]
|
||||||
state: EitherExtractState<L, R>,
|
state: EitherExtractState<L, R>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project::pin_project(project = EitherExtractProj)]
|
pin_project! {
|
||||||
pub enum EitherExtractState<L, R>
|
#[project = EitherExtractProj]
|
||||||
where
|
pub enum EitherExtractState<L, R>
|
||||||
L: FromRequest,
|
where
|
||||||
R: FromRequest,
|
L: FromRequest,
|
||||||
{
|
R: FromRequest,
|
||||||
Bytes {
|
{
|
||||||
#[pin]
|
Bytes {
|
||||||
bytes: <Bytes as FromRequest>::Future,
|
#[pin]
|
||||||
},
|
bytes: <Bytes as FromRequest>::Future,
|
||||||
Left {
|
},
|
||||||
#[pin]
|
Left {
|
||||||
left: L::Future,
|
#[pin]
|
||||||
fallback: Bytes,
|
left: L::Future,
|
||||||
},
|
fallback: Bytes,
|
||||||
Right {
|
},
|
||||||
#[pin]
|
Right {
|
||||||
right: R::Future,
|
#[pin]
|
||||||
left_err: Option<L::Error>,
|
right: R::Future,
|
||||||
},
|
left_err: Option<L::Error>,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, RF, RE, L, LF, LE> Future for EitherExtractFut<L, R>
|
impl<R, RF, RE, L, LF, LE> Future for EitherExtractFut<L, R>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user