1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-26 22:07:42 +02:00

remove pin-project; update Unpin consrtaint

This commit is contained in:
Nikolay Kim
2019-11-18 18:28:54 +06:00
parent 7404d82a9b
commit 1354946460
22 changed files with 225 additions and 161 deletions

View File

@ -154,10 +154,8 @@ where
InitError = A::InitError,
>,
A::Future: Unpin,
A::Service: Unpin,
<A::Service as Service>::Future: Unpin,
B::Future: Unpin,
B::Service: Unpin,
<B::Service as Service>::Future: Unpin,
{
type Request = A::Request;
@ -204,10 +202,8 @@ where
A: ServiceFactory,
B: ServiceFactory<Request = A::Response>,
A::Future: Unpin,
A::Service: Unpin,
<A::Service as Service>::Future: Unpin,
B::Future: Unpin,
B::Service: Unpin,
<B::Service as Service>::Future: Unpin,
{
fn new(fut_a: A::Future, fut_b: B::Future) -> Self {
@ -220,15 +216,24 @@ where
}
}
impl<A, B> Unpin for AndThenServiceFactoryResponse<A, B>
where
A: ServiceFactory,
B: ServiceFactory<Request = A::Response, Error = A::Error, InitError = A::InitError>,
A::Future: Unpin,
<A::Service as Service>::Future: Unpin,
B::Future: Unpin,
<B::Service as Service>::Future: Unpin,
{
}
impl<A, B> Future for AndThenServiceFactoryResponse<A, B>
where
A: ServiceFactory,
B: ServiceFactory<Request = A::Response, Error = A::Error, InitError = A::InitError>,
A::Future: Unpin,
A::Service: Unpin,
<A::Service as Service>::Future: Unpin,
B::Future: Unpin,
B::Service: Unpin,
<B::Service as Service>::Future: Unpin,
{
type Output = Result<AndThenService<A::Service, B::Service>, A::InitError>;

View File

@ -23,7 +23,8 @@ pub fn apply_fn_factory<T, F, R, In, Out, Err, U>(
) -> ApplyServiceFactory<T, F, R, In, Out, Err>
where
T: ServiceFactory<Error = Err>,
F: FnMut(In, &mut T::Service) -> R + Clone,
T::Future: Unpin,
F: FnMut(In, &mut T::Service) -> R + Unpin + Clone,
R: Future<Output = Result<Out, Err>>,
U: IntoServiceFactory<T>,
{

View File

@ -73,7 +73,6 @@ pub trait Service {
fn map<F, R>(self, f: F) -> crate::dev::Map<Self, F, R>
where
Self: Sized,
Self::Future: Unpin,
F: FnMut(Self::Response) -> R + Unpin,
{
crate::dev::Map::new(self, f)
@ -90,7 +89,6 @@ pub trait Service {
fn map_err<F, E>(self, f: F) -> crate::dev::MapErr<Self, F, E>
where
Self: Sized,
Self::Future: Unpin,
F: Fn(Self::Error) -> E,
{
crate::dev::MapErr::new(self, f)
@ -140,7 +138,6 @@ pub trait ServiceFactory {
fn map<F, R>(self, f: F) -> crate::map::MapServiceFactory<Self, F, R>
where
Self: Sized,
<Self::Service as Service>::Future: Unpin,
F: FnMut(Self::Response) -> R + Unpin + Clone,
{
crate::map::MapServiceFactory::new(self, f)
@ -150,7 +147,6 @@ pub trait ServiceFactory {
fn map_err<F, E>(self, f: F) -> crate::map_err::MapErrServiceFactory<Self, F, E>
where
Self: Sized,
<Self::Service as Service>::Future: Unpin,
F: Fn(Self::Error) -> E + Unpin + Clone,
{
crate::map_err::MapErrServiceFactory::new(self, f)
@ -160,7 +156,6 @@ pub trait ServiceFactory {
fn map_init_err<F, E>(self, f: F) -> crate::map_init_err::MapInitErr<Self, F, E>
where
Self: Sized,
<Self::Service as Service>::Future: Unpin,
F: Fn(Self::InitError) -> E + Unpin + Clone,
{
crate::map_init_err::MapInitErr::new(self, f)
@ -299,6 +294,7 @@ pub mod dev {
FnService, FnServiceConfig, FnServiceFactory, FnServiceNoConfig,
};
pub use crate::map::{Map, MapServiceFactory};
pub use crate::map_config::{MapConfig, UnitConfig};
pub use crate::map_err::{MapErr, MapErrServiceFactory};
pub use crate::map_init_err::MapInitErr;
pub use crate::then::{ThenService, ThenServiceFactory};

View File

@ -8,16 +8,7 @@ pub enum MappedConfig<'a, T> {
}
/// Adapt external config to a config for provided new service
pub fn map_config<T, F, C>(
factory: T,
f: F,
) -> impl ServiceFactory<
Config = C,
Request = T::Request,
Response = T::Response,
Error = T::Error,
InitError = T::InitError,
>
pub fn map_config<T, F, C>(factory: T, f: F) -> MapConfig<T, F, C>
where
T: ServiceFactory,
F: Fn(&C) -> MappedConfig<T::Config>,
@ -26,23 +17,15 @@ where
}
/// Replace config with unit
pub fn unit_config<T, C>(
new_service: T,
) -> impl ServiceFactory<
Config = C,
Request = T::Request,
Response = T::Response,
Error = T::Error,
InitError = T::InitError,
>
pub fn unit_config<T, C>(new_service: T) -> UnitConfig<T, C>
where
T: ServiceFactory<Config = ()>,
{
UnitConfig::new(new_service)
}
/// `MapInitErr` service combinator
pub(crate) struct MapConfig<A, F, C> {
/// `.map_config()` service combinator
pub struct MapConfig<A, F, C> {
a: A,
f: F,
e: PhantomData<C>,
@ -50,7 +33,7 @@ pub(crate) struct MapConfig<A, F, C> {
impl<A, F, C> MapConfig<A, F, C> {
/// Create new `MapConfig` combinator
pub fn new(a: A, f: F) -> Self
pub(crate) fn new(a: A, f: F) -> Self
where
A: ServiceFactory,
F: Fn(&C) -> MappedConfig<A::Config>,
@ -99,8 +82,8 @@ where
}
}
/// `MapInitErr` service combinator
pub(crate) struct UnitConfig<A, C> {
/// `unit_config()` config combinator
pub struct UnitConfig<A, C> {
a: A,
e: PhantomData<C>,
}

View File

@ -43,7 +43,7 @@ impl<T: Service> Pipeline<T> {
where
Self: Sized,
F: IntoService<U>,
U: Service<Request = T::Response, Error = T::Error> + Unpin,
U: Service<Request = T::Response, Error = T::Error>,
{
Pipeline {
service: AndThenService::new(self.service, service.into_service()),

View File

@ -149,10 +149,8 @@ where
InitError = A::InitError,
>,
A::Future: Unpin,
A::Service: Unpin,
<A::Service as Service>::Future: Unpin,
B::Future: Unpin,
B::Service: Unpin,
<B::Service as Service>::Future: Unpin,
{
type Request = A::Request;
@ -208,10 +206,8 @@ where
InitError = A::InitError,
>,
A::Future: Unpin,
A::Service: Unpin,
<A::Service as Service>::Future: Unpin,
B::Future: Unpin,
B::Service: Unpin,
<B::Service as Service>::Future: Unpin,
{
fn new(fut_a: A::Future, fut_b: B::Future) -> Self {
@ -224,6 +220,22 @@ where
}
}
impl<A, B> Unpin for ThenServiceFactoryResponse<A, B>
where
A: ServiceFactory,
B: ServiceFactory<
Config = A::Config,
Request = Result<A::Response, A::Error>,
Error = A::Error,
InitError = A::InitError,
>,
A::Future: Unpin,
<A::Service as Service>::Future: Unpin,
B::Future: Unpin,
<B::Service as Service>::Future: Unpin,
{
}
impl<A, B> Future for ThenServiceFactoryResponse<A, B>
where
A: ServiceFactory,
@ -234,10 +246,8 @@ where
InitError = A::InitError,
>,
A::Future: Unpin,
A::Service: Unpin,
<A::Service as Service>::Future: Unpin,
B::Future: Unpin,
B::Service: Unpin,
<B::Service as Service>::Future: Unpin,
{
type Output = Result<ThenService<A::Service, B::Service>, A::InitError>;