rename Factor to ServiceFactory

This commit is contained in:
Nikolay Kim 2019-11-12 11:09:19 +06:00
parent 8e882f0c37
commit 4c1cefefe6
19 changed files with 175 additions and 171 deletions

View File

@ -17,7 +17,7 @@ use tokio_timer::delay;
use crate::accept::{AcceptLoop, AcceptNotify, Command};
use crate::config::{ConfiguredService, ServiceConfig};
use crate::server::{Server, ServerCommand};
use crate::services::{InternalServiceFactory, ServiceFactory, StreamNewService};
use crate::service::{InternalServiceFactory, ServiceFactory, StreamNewService};
// use crate::signals::{Signal, Signals};
use crate::socket::StdListener;
use crate::worker::{self, Worker, WorkerAvailability, WorkerClient};

View File

@ -2,13 +2,13 @@ use std::collections::HashMap;
use std::{fmt, io, net};
use actix_server_config::{Io, ServerConfig};
use actix_service::{Factory, IntoFactory};
use actix_service as actix;
use futures::future::{Future, FutureExt, LocalBoxFuture};
use log::error;
use tokio_net::tcp::TcpStream;
use super::builder::bind_addr;
use super::services::{
use super::service::{
BoxedServerService, InternalServiceFactory, ServerMessage, StreamService,
};
use super::Token;
@ -195,8 +195,8 @@ impl ServiceRuntime {
/// *ServiceConfig::bind()* or *ServiceConfig::listen()* methods.
pub fn service<T, F>(&mut self, name: &str, service: F)
where
F: IntoFactory<T>,
T: Factory<Config = ServerConfig, Request = Io<TcpStream>> + 'static,
F: actix::IntoServiceFactory<T>,
T: actix::ServiceFactory<Config = ServerConfig, Request = Io<TcpStream>> + 'static,
T::Future: 'static,
T::Service: 'static,
T::InitError: fmt::Debug,
@ -224,7 +224,7 @@ impl ServiceRuntime {
}
type BoxedNewService = Box<
dyn Factory<
dyn actix::ServiceFactory<
Request = (Option<CounterGuard>, ServerMessage),
Response = (),
Error = (),
@ -239,9 +239,9 @@ struct ServiceFactory<T> {
inner: T,
}
impl<T> Factory for ServiceFactory<T>
impl<T> actix::ServiceFactory for ServiceFactory<T>
where
T: Factory<Config = ServerConfig, Request = Io<TcpStream>>,
T: actix::ServiceFactory<Config = ServerConfig, Request = Io<TcpStream>>,
T::Future: 'static,
T::Service: 'static,
T::Error: 'static,

View File

@ -5,7 +5,7 @@ mod builder;
mod config;
mod counter;
mod server;
mod services;
mod service;
// mod signals;
mod socket;
pub mod ssl;
@ -16,14 +16,11 @@ pub use actix_server_config::{Io, IoStream, Protocol, ServerConfig};
pub use self::builder::ServerBuilder;
pub use self::config::{ServiceConfig, ServiceRuntime};
pub use self::server::Server;
pub use self::services::ServiceFactory;
pub use self::service::ServiceFactory;
#[doc(hidden)]
pub use self::socket::FromStream;
#[doc(hidden)]
pub use self::services::ServiceFactory as StreamServiceFactory;
/// Socket id token
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) struct Token(usize);

View File

@ -5,7 +5,7 @@ use std::time::Duration;
use actix_rt::spawn;
use actix_server_config::{Io, ServerConfig};
use actix_service::{Factory, Service};
use actix_service::{self as actix, Service, ServiceFactory as ActixServiceFactory};
use futures::future::{err, ok, LocalBoxFuture, Ready};
use futures::{FutureExt, TryFutureExt};
use log::error;
@ -25,7 +25,7 @@ pub(crate) enum ServerMessage {
}
pub trait ServiceFactory<Stream: FromStream>: Send + Clone + 'static {
type NewService: Factory<Config = ServerConfig, Request = Io<Stream>>;
type NewService: actix::ServiceFactory<Config = ServerConfig, Request = Io<Stream>>;
fn create(&self) -> Self::NewService;
}
@ -180,7 +180,7 @@ impl InternalServiceFactory for Box<dyn InternalServiceFactory> {
impl<F, T, I> ServiceFactory<I> for F
where
F: Fn() -> T + Send + Clone + 'static,
T: Factory<Config = ServerConfig, Request = Io<I>>,
T: actix::ServiceFactory<Config = ServerConfig, Request = Io<I>>,
I: FromStream,
{
type NewService = T;

View File

@ -14,7 +14,7 @@ use tokio_timer::{delay, Delay};
use crate::accept::AcceptNotify;
use crate::counter::Counter;
use crate::services::{BoxedServerService, InternalServiceFactory, ServerMessage};
use crate::service::{BoxedServerService, InternalServiceFactory, ServerMessage};
use crate::socket::{SocketAddr, StdStream};
use crate::Token;

View File

@ -4,7 +4,7 @@ use std::task::{Context, Poll};
use pin_project::pin_project;
use super::{Factory, Service};
use super::{Service, ServiceFactory};
use crate::cell::Cell;
/// Service for the `and_then` combinator, chaining a computation onto the end
@ -129,8 +129,8 @@ where
/// `AndThenNewService` new service combinator
pub struct AndThenNewService<A, B>
where
A: Factory,
B: Factory,
A: ServiceFactory,
B: ServiceFactory,
{
a: A,
b: B,
@ -138,8 +138,8 @@ where
impl<A, B> AndThenNewService<A, B>
where
A: Factory,
B: Factory<
A: ServiceFactory,
B: ServiceFactory<
Config = A::Config,
Request = A::Response,
Error = A::Error,
@ -152,10 +152,10 @@ where
}
}
impl<A, B> Factory for AndThenNewService<A, B>
impl<A, B> ServiceFactory for AndThenNewService<A, B>
where
A: Factory,
B: Factory<
A: ServiceFactory,
B: ServiceFactory<
Config = A::Config,
Request = A::Response,
Error = A::Error,
@ -178,8 +178,8 @@ where
impl<A, B> Clone for AndThenNewService<A, B>
where
A: Factory + Clone,
B: Factory + Clone,
A: ServiceFactory + Clone,
B: ServiceFactory + Clone,
{
fn clone(&self) -> Self {
Self {
@ -192,8 +192,8 @@ where
#[pin_project]
pub struct AndThenNewServiceFuture<A, B>
where
A: Factory,
B: Factory<Request = A::Response>,
A: ServiceFactory,
B: ServiceFactory<Request = A::Response>,
{
#[pin]
fut_b: B::Future,
@ -206,8 +206,8 @@ where
impl<A, B> AndThenNewServiceFuture<A, B>
where
A: Factory,
B: Factory<Request = A::Response>,
A: ServiceFactory,
B: ServiceFactory<Request = A::Response>,
{
fn new(fut_a: A::Future, fut_b: B::Future) -> Self {
AndThenNewServiceFuture {
@ -221,8 +221,8 @@ where
impl<A, B> Future for AndThenNewServiceFuture<A, B>
where
A: Factory,
B: Factory<Request = A::Response, Error = A::Error, InitError = A::InitError>,
A: ServiceFactory,
B: ServiceFactory<Request = A::Response, Error = A::Error, InitError = A::InitError>,
{
type Output = Result<AndThen<A::Service, B::Service>, A::InitError>;

View File

@ -4,7 +4,7 @@ use std::marker::PhantomData;
use std::pin::Pin;
use std::task::{Context, Poll};
use super::{Factory, IntoFactory, IntoService, Service};
use super::{IntoService, IntoServiceFactory, Service, ServiceFactory};
/// Apply tranform function to a service
pub fn apply_fn<T, F, R, In, Out, Err, U>(
@ -24,12 +24,12 @@ where
pub fn apply_fn_factory<T, F, R, In, Out, Err, U>(
service: U,
f: F,
) -> impl Factory<Request = In, Response = Out, Error = Err>
) -> impl ServiceFactory<Request = In, Response = Out, Error = Err>
where
T: Factory<Error = Err>,
T: ServiceFactory<Error = Err>,
F: FnMut(In, &mut T::Service) -> R + Clone,
R: Future<Output = Result<Out, Err>>,
U: IntoFactory<T>,
U: IntoServiceFactory<T>,
{
ApplyNewService::new(service.into_factory(), f)
}
@ -86,7 +86,7 @@ where
/// `ApplyNewService` new service combinator
struct ApplyNewService<T, F, R, In, Out, Err>
where
T: Factory<Error = Err>,
T: ServiceFactory<Error = Err>,
{
service: T,
f: F,
@ -95,7 +95,7 @@ where
impl<T, F, R, In, Out, Err> ApplyNewService<T, F, R, In, Out, Err>
where
T: Factory<Error = Err>,
T: ServiceFactory<Error = Err>,
F: FnMut(In, &mut T::Service) -> R + Clone,
R: Future<Output = Result<Out, Err>>,
{
@ -109,9 +109,9 @@ where
}
}
impl<T, F, R, In, Out, Err> Factory for ApplyNewService<T, F, R, In, Out, Err>
impl<T, F, R, In, Out, Err> ServiceFactory for ApplyNewService<T, F, R, In, Out, Err>
where
T: Factory<Error = Err>,
T: ServiceFactory<Error = Err>,
F: FnMut(In, &mut T::Service) -> R + Clone,
R: Future<Output = Result<Out, Err>>,
{
@ -132,7 +132,7 @@ where
#[pin_project]
struct ApplyNewServiceFuture<T, F, R, In, Out, Err>
where
T: Factory<Error = Err>,
T: ServiceFactory<Error = Err>,
F: FnMut(In, &mut T::Service) -> R + Clone,
R: Future<Output = Result<Out, Err>>,
{
@ -144,7 +144,7 @@ where
impl<T, F, R, In, Out, Err> ApplyNewServiceFuture<T, F, R, In, Out, Err>
where
T: Factory<Error = Err>,
T: ServiceFactory<Error = Err>,
F: FnMut(In, &mut T::Service) -> R + Clone,
R: Future<Output = Result<Out, Err>>,
{
@ -159,7 +159,7 @@ where
impl<T, F, R, In, Out, Err> Future for ApplyNewServiceFuture<T, F, R, In, Out, Err>
where
T: Factory<Error = Err>,
T: ServiceFactory<Error = Err>,
F: FnMut(In, &mut T::Service) -> R + Clone,
R: Future<Output = Result<Out, Err>>,
{

View File

@ -7,13 +7,13 @@ use futures::ready;
use pin_project::pin_project;
use crate::cell::Cell;
use crate::{Factory, IntoService, Service};
use crate::{IntoService, Service, ServiceFactory};
/// Convert `Fn(&Config, &mut Service) -> Future<Service>` fn to a NewService
pub fn apply_cfg<F, C, T, R, S, E>(
srv: T,
f: F,
) -> impl Factory<
) -> impl ServiceFactory<
Config = C,
Request = S::Request,
Response = S::Response,
@ -39,7 +39,7 @@ where
pub fn apply_cfg_factory<F, C, T, R, S>(
srv: T,
f: F,
) -> impl Factory<
) -> impl ServiceFactory<
Config = C,
Request = S::Request,
Response = S::Response,
@ -50,7 +50,7 @@ pub fn apply_cfg_factory<F, C, T, R, S>(
where
C: Clone,
F: FnMut(&C, &mut T::Service) -> R,
T: Factory<Config = ()>,
T: ServiceFactory<Config = ()>,
T::InitError: From<T::Error>,
R: Future<Output = Result<S, T::InitError>>,
S: Service,
@ -93,7 +93,7 @@ where
}
}
impl<F, C, T, R, S, E> Factory for ApplyConfigService<F, C, T, R, S, E>
impl<F, C, T, R, S, E> ServiceFactory for ApplyConfigService<F, C, T, R, S, E>
where
F: FnMut(&C, &mut T) -> R,
T: Service,
@ -145,7 +145,7 @@ struct ApplyConfigNewService<F, C, T, R, S>
where
C: Clone,
F: FnMut(&C, &mut T::Service) -> R,
T: Factory<Config = ()>,
T: ServiceFactory<Config = ()>,
R: Future<Output = Result<S, T::InitError>>,
S: Service,
{
@ -158,7 +158,7 @@ impl<F, C, T, R, S> Clone for ApplyConfigNewService<F, C, T, R, S>
where
C: Clone,
F: FnMut(&C, &mut T::Service) -> R,
T: Factory<Config = ()>,
T: ServiceFactory<Config = ()>,
R: Future<Output = Result<S, T::InitError>>,
S: Service,
{
@ -171,11 +171,11 @@ where
}
}
impl<F, C, T, R, S> Factory for ApplyConfigNewService<F, C, T, R, S>
impl<F, C, T, R, S> ServiceFactory for ApplyConfigNewService<F, C, T, R, S>
where
C: Clone,
F: FnMut(&C, &mut T::Service) -> R,
T: Factory<Config = ()>,
T: ServiceFactory<Config = ()>,
T::InitError: From<T::Error>,
R: Future<Output = Result<S, T::InitError>>,
S: Service,
@ -206,7 +206,7 @@ struct ApplyConfigNewServiceFut<F, C, T, R, S>
where
C: Clone,
F: FnMut(&C, &mut T::Service) -> R,
T: Factory<Config = ()>,
T: ServiceFactory<Config = ()>,
T::InitError: From<T::Error>,
R: Future<Output = Result<S, T::InitError>>,
S: Service,
@ -225,7 +225,7 @@ impl<F, C, T, R, S> Future for ApplyConfigNewServiceFut<F, C, T, R, S>
where
C: Clone,
F: FnMut(&C, &mut T::Service) -> R,
T: Factory<Config = ()>,
T: ServiceFactory<Config = ()>,
T::InitError: From<T::Error>,
R: Future<Output = Result<S, T::InitError>>,
S: Service,

View File

@ -7,7 +7,7 @@ use std::task::{Context, Poll};
use futures::future::{err, ok, Either, Ready};
use futures::future::{FutureExt, LocalBoxFuture};
use crate::{Factory, Service};
use crate::{Service, ServiceFactory};
pub type BoxedService<Req, Res, Err> = Box<
dyn Service<
@ -28,7 +28,7 @@ pub fn factory<T>(
factory: T,
) -> BoxedNewService<T::Config, T::Request, T::Response, T::Error, T::InitError>
where
T: Factory + 'static,
T: ServiceFactory + 'static,
T::Request: 'static,
T::Response: 'static,
T::Service: 'static,
@ -52,7 +52,7 @@ where
}
type Inner<C, Req, Res, Err, InitErr> = Box<
dyn Factory<
dyn ServiceFactory<
Config = C,
Request = Req,
Response = Res,
@ -63,7 +63,7 @@ type Inner<C, Req, Res, Err, InitErr> = Box<
>,
>;
impl<C, Req, Res, Err, InitErr> Factory for BoxedNewService<C, Req, Res, Err, InitErr>
impl<C, Req, Res, Err, InitErr> ServiceFactory for BoxedNewService<C, Req, Res, Err, InitErr>
where
Req: 'static,
Res: 'static,
@ -84,18 +84,24 @@ where
}
}
struct FactoryWrapper<C, T: Factory> {
struct FactoryWrapper<C, T: ServiceFactory> {
factory: T,
_t: std::marker::PhantomData<C>,
}
impl<C, T, Req, Res, Err, InitErr> Factory for FactoryWrapper<C, T>
impl<C, T, Req, Res, Err, InitErr> ServiceFactory for FactoryWrapper<C, T>
where
Req: 'static,
Res: 'static,
Err: 'static,
InitErr: 'static,
T: Factory<Config = C, Request = Req, Response = Res, Error = Err, InitError = InitErr>,
T: ServiceFactory<
Config = C,
Request = Req,
Response = Res,
Error = Err,
InitError = InitErr,
>,
T::Future: 'static,
T::Service: 'static,
<T::Service as Service>::Future: 'static,

View File

@ -6,12 +6,13 @@ use std::task::{Context, Poll};
use futures::future::{ok, Ready};
use pin_project::pin_project;
use crate::{Factory, IntoFactory, IntoService, Service};
use crate::{IntoService, IntoServiceFactory, Service, ServiceFactory};
/// Create `Factory` for function that can act as a Service
/// Create `ServiceFactory` for function that can act as a Service
pub fn service_fn<F, Fut, Req, Res, Err, Cfg>(
f: F,
) -> impl Factory<Config = Cfg, Request = Req, Response = Res, Error = Err, InitError = ()> + Clone
) -> impl ServiceFactory<Config = Cfg, Request = Req, Response = Res, Error = Err, InitError = ()>
+ Clone
where
F: FnMut(Req) -> Fut + Clone,
Fut: Future<Output = Result<Res, Err>>,
@ -19,10 +20,10 @@ where
NewServiceFn::new(f)
}
/// Create `Factory` for function that can produce services
/// Create `ServiceFactory` for function that can produce services
pub fn service_fn_factory<S, F, Cfg, Fut, Err>(
f: F,
) -> impl Factory<
) -> impl ServiceFactory<
Config = Cfg,
Request = S::Request,
Response = S::Response,
@ -38,10 +39,10 @@ where
FnNewServiceNoConfig::new(f)
}
/// Create `Factory` for function that can produce services with configuration
/// Create `ServiceFactory` for function that can produce services with configuration
pub fn service_fn_config<F, Fut, Cfg, Srv, Err>(
f: F,
) -> impl Factory<
) -> impl ServiceFactory<
Config = Cfg,
Request = Srv::Request,
Response = Srv::Response,
@ -143,7 +144,7 @@ where
}
}
impl<F, Fut, Req, Res, Err, Cfg> Factory for NewServiceFn<F, Fut, Req, Res, Err, Cfg>
impl<F, Fut, Req, Res, Err, Cfg> ServiceFactory for NewServiceFn<F, Fut, Req, Res, Err, Cfg>
where
F: FnMut(Req) -> Fut + Clone,
Fut: Future<Output = Result<Res, Err>>,
@ -184,7 +185,7 @@ where
}
}
impl<F, Fut, Cfg, Srv, Err> Factory for FnNewServiceConfig<F, Fut, Cfg, Srv, Err>
impl<F, Fut, Cfg, Srv, Err> ServiceFactory for FnNewServiceConfig<F, Fut, Cfg, Srv, Err>
where
F: Fn(&Cfg) -> Fut,
Fut: Future<Output = Result<Srv, Err>>,
@ -252,7 +253,7 @@ where
}
}
impl<F, C, R, S, E> Factory for FnNewServiceNoConfig<F, C, R, S, E>
impl<F, C, R, S, E> ServiceFactory for FnNewServiceNoConfig<F, C, R, S, E>
where
F: Fn() -> R,
R: Future<Output = Result<S, E>>,
@ -282,7 +283,7 @@ where
}
}
impl<F, C, R, S, E> IntoFactory<FnNewServiceNoConfig<F, C, R, S, E>> for F
impl<F, C, R, S, E> IntoServiceFactory<FnNewServiceNoConfig<F, C, R, S, E>> for F
where
F: Fn() -> R,
R: Future<Output = Result<S, E>>,

View File

@ -3,7 +3,7 @@ use std::task::{Context, Poll};
use crate::map::{Map, MapNewService};
use crate::map_err::{MapErr, MapErrNewService};
use crate::map_init_err::MapInitErr;
use crate::{Factory, IntoFactory, IntoService, Service};
use crate::{IntoService, IntoServiceFactory, Service, ServiceFactory};
#[inline]
/// Convert object of type `U` to a service `T`
@ -17,12 +17,12 @@ where
}
}
pub fn into_factory<T, F>(factory: F) -> FactoryMapper<T>
pub fn into_factory<T, F>(factory: F) -> ServiceFactoryMapper<T>
where
T: Factory,
F: IntoFactory<T>,
T: ServiceFactory,
F: IntoServiceFactory<T>,
{
FactoryMapper {
ServiceFactoryMapper {
factory: factory.into_factory(),
}
}
@ -31,7 +31,7 @@ pub struct ServiceMapper<T> {
service: T,
}
pub struct FactoryMapper<T> {
pub struct ServiceFactoryMapper<T> {
factory: T,
}
@ -108,14 +108,14 @@ impl<T: Service> Service for ServiceMapper<T> {
}
}
impl<T: Factory> FactoryMapper<T> {
impl<T: ServiceFactory> ServiceFactoryMapper<T> {
/// Map this service's output to a different type, returning a new service
/// of the resulting type.
pub fn map<F, R>(
self,
f: F,
) -> FactoryMapper<
impl Factory<
) -> ServiceFactoryMapper<
impl ServiceFactory<
Config = T::Config,
Request = T::Request,
Response = R,
@ -127,7 +127,7 @@ impl<T: Factory> FactoryMapper<T> {
Self: Sized,
F: FnMut(T::Response) -> R + Clone,
{
FactoryMapper {
ServiceFactoryMapper {
factory: MapNewService::new(self.factory, f),
}
}
@ -136,8 +136,8 @@ impl<T: Factory> FactoryMapper<T> {
pub fn map_err<F, E>(
self,
f: F,
) -> FactoryMapper<
impl Factory<
) -> ServiceFactoryMapper<
impl ServiceFactory<
Config = T::Config,
Request = T::Request,
Response = T::Response,
@ -149,7 +149,7 @@ impl<T: Factory> FactoryMapper<T> {
Self: Sized,
F: Fn(T::Error) -> E + Clone,
{
FactoryMapper {
ServiceFactoryMapper {
factory: MapErrNewService::new(self.factory, f),
}
}
@ -158,8 +158,8 @@ impl<T: Factory> FactoryMapper<T> {
pub fn map_init_err<F, E>(
self,
f: F,
) -> FactoryMapper<
impl Factory<
) -> ServiceFactoryMapper<
impl ServiceFactory<
Config = T::Config,
Request = T::Request,
Response = T::Response,
@ -171,24 +171,24 @@ impl<T: Factory> FactoryMapper<T> {
Self: Sized,
F: Fn(T::InitError) -> E + Clone,
{
FactoryMapper {
ServiceFactoryMapper {
factory: MapInitErr::new(self.factory, f),
}
}
}
impl<T> Clone for FactoryMapper<T>
impl<T> Clone for ServiceFactoryMapper<T>
where
T: Clone,
{
fn clone(&self) -> Self {
FactoryMapper {
ServiceFactoryMapper {
factory: self.factory.clone(),
}
}
}
impl<T: Factory> Factory for FactoryMapper<T> {
impl<T: ServiceFactory> ServiceFactory for ServiceFactoryMapper<T> {
type Config = T::Config;
type Request = T::Request;
type Response = T::Response;

View File

@ -23,7 +23,7 @@ mod transform_err;
pub use self::apply::{apply_fn, apply_fn_factory};
pub use self::apply_cfg::{apply_cfg, apply_cfg_factory};
pub use self::fn_service::{service_fn, service_fn_config, service_fn_factory};
pub use self::into::{into_factory, into_service, FactoryMapper, ServiceMapper};
pub use self::into::{into_factory, into_service, ServiceFactoryMapper, ServiceMapper};
pub use self::map_config::{map_config, unit_config, MappedConfig};
pub use self::pipeline::{pipeline, pipeline_factory, Pipeline, PipelineFactory};
pub use self::transform::{apply_transform, IntoTransform, Transform};
@ -74,7 +74,7 @@ pub trait Service {
/// requests on that new TCP stream.
///
/// `Config` is a service factory configuration type.
pub trait Factory {
pub trait ServiceFactory {
/// Requests handled by the service.
type Request;
@ -158,9 +158,9 @@ where
}
}
impl<S> Factory for Rc<S>
impl<S> ServiceFactory for Rc<S>
where
S: Factory,
S: ServiceFactory,
{
type Request = S::Request;
type Response = S::Response;
@ -175,9 +175,9 @@ where
}
}
impl<S> Factory for Arc<S>
impl<S> ServiceFactory for Arc<S>
where
S: Factory,
S: ServiceFactory,
{
type Request = S::Request;
type Response = S::Response;
@ -201,10 +201,10 @@ where
fn into_service(self) -> T;
}
/// Trait for types that can be converted to a `Factory`
pub trait IntoFactory<T>
/// Trait for types that can be converted to a `ServiceFactory`
pub trait IntoServiceFactory<T>
where
T: Factory,
T: ServiceFactory,
{
/// Convert `Self` an `ServiceFactory`
fn into_factory(self) -> T;
@ -219,9 +219,9 @@ where
}
}
impl<T> IntoFactory<T> for T
impl<T> IntoServiceFactory<T> for T
where
T: Factory,
T: ServiceFactory,
{
fn into_factory(self) -> T {
self

View File

@ -5,7 +5,7 @@ use std::task::{Context, Poll};
use pin_project::pin_project;
use super::{Factory, Service};
use super::{Service, ServiceFactory};
/// Service for the `map` combinator, changing the type of a service's response.
///
@ -113,7 +113,7 @@ impl<A, F, Res> MapNewService<A, F, Res> {
/// Create new `Map` new service instance
pub fn new(a: A, f: F) -> Self
where
A: Factory,
A: ServiceFactory,
F: FnMut(A::Response) -> Res,
{
Self {
@ -138,9 +138,9 @@ where
}
}
impl<A, F, Res> Factory for MapNewService<A, F, Res>
impl<A, F, Res> ServiceFactory for MapNewService<A, F, Res>
where
A: Factory,
A: ServiceFactory,
F: FnMut(A::Response) -> Res + Clone,
{
type Request = A::Request;
@ -160,7 +160,7 @@ where
#[pin_project]
pub(crate) struct MapNewServiceFuture<A, F, Res>
where
A: Factory,
A: ServiceFactory,
F: FnMut(A::Response) -> Res,
{
#[pin]
@ -170,7 +170,7 @@ where
impl<A, F, Res> MapNewServiceFuture<A, F, Res>
where
A: Factory,
A: ServiceFactory,
F: FnMut(A::Response) -> Res,
{
fn new(fut: A::Future, f: F) -> Self {
@ -180,7 +180,7 @@ where
impl<A, F, Res> Future for MapNewServiceFuture<A, F, Res>
where
A: Factory,
A: ServiceFactory,
F: FnMut(A::Response) -> Res,
{
type Output = Result<Map<A::Service, F, Res>, A::InitError>;
@ -200,7 +200,7 @@ mod tests {
use futures::future::{ok, Ready};
use super::*;
use crate::{IntoFactory, Service};
use crate::{IntoServiceFactory, Service};
struct Srv;

View File

@ -1,6 +1,6 @@
use std::marker::PhantomData;
use super::Factory;
use super::ServiceFactory;
pub enum MappedConfig<'a, T> {
Ref(&'a T),
@ -11,7 +11,7 @@ pub enum MappedConfig<'a, T> {
pub fn map_config<T, F, C>(
factory: T,
f: F,
) -> impl Factory<
) -> impl ServiceFactory<
Config = C,
Request = T::Request,
Response = T::Response,
@ -19,7 +19,7 @@ pub fn map_config<T, F, C>(
InitError = T::InitError,
>
where
T: Factory,
T: ServiceFactory,
F: Fn(&C) -> MappedConfig<T::Config>,
{
MapConfig::new(factory, f)
@ -28,7 +28,7 @@ where
/// Replace config with unit
pub fn unit_config<T, C>(
new_service: T,
) -> impl Factory<
) -> impl ServiceFactory<
Config = C,
Request = T::Request,
Response = T::Response,
@ -36,7 +36,7 @@ pub fn unit_config<T, C>(
InitError = T::InitError,
>
where
T: Factory<Config = ()>,
T: ServiceFactory<Config = ()>,
{
UnitConfig::new(new_service)
}
@ -52,7 +52,7 @@ impl<A, F, C> MapConfig<A, F, C> {
/// Create new `MapConfig` combinator
pub fn new(a: A, f: F) -> Self
where
A: Factory,
A: ServiceFactory,
F: Fn(&C) -> MappedConfig<A::Config>,
{
Self {
@ -77,9 +77,9 @@ where
}
}
impl<A, F, C> Factory for MapConfig<A, F, C>
impl<A, F, C> ServiceFactory for MapConfig<A, F, C>
where
A: Factory,
A: ServiceFactory,
F: Fn(&C) -> MappedConfig<A::Config>,
{
type Request = A::Request;
@ -107,7 +107,7 @@ pub(crate) struct UnitConfig<A, C> {
impl<A, C> UnitConfig<A, C>
where
A: Factory<Config = ()>,
A: ServiceFactory<Config = ()>,
{
/// Create new `UnitConfig` combinator
pub(crate) fn new(a: A) -> Self {
@ -127,9 +127,9 @@ where
}
}
impl<A, C> Factory for UnitConfig<A, C>
impl<A, C> ServiceFactory for UnitConfig<A, C>
where
A: Factory<Config = ()>,
A: ServiceFactory<Config = ()>,
{
type Request = A::Request;
type Response = A::Response;

View File

@ -5,7 +5,7 @@ use std::task::{Context, Poll};
use pin_project::pin_project;
use super::{Factory, Service};
use super::{Service, ServiceFactory};
/// Service for the `map_err` combinator, changing the type of a service's
/// error.
@ -105,7 +105,7 @@ where
/// This is created by the `NewServiceExt::map_err` method.
pub(crate) struct MapErrNewService<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::Error) -> E + Clone,
{
a: A,
@ -115,7 +115,7 @@ where
impl<A, F, E> MapErrNewService<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::Error) -> E + Clone,
{
/// Create new `MapErr` new service instance
@ -130,7 +130,7 @@ where
impl<A, F, E> Clone for MapErrNewService<A, F, E>
where
A: Factory + Clone,
A: ServiceFactory + Clone,
F: Fn(A::Error) -> E + Clone,
{
fn clone(&self) -> Self {
@ -142,9 +142,9 @@ where
}
}
impl<A, F, E> Factory for MapErrNewService<A, F, E>
impl<A, F, E> ServiceFactory for MapErrNewService<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::Error) -> E + Clone,
{
type Request = A::Request;
@ -164,7 +164,7 @@ where
#[pin_project]
pub(crate) struct MapErrNewServiceFuture<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::Error) -> E,
{
#[pin]
@ -174,7 +174,7 @@ where
impl<A, F, E> MapErrNewServiceFuture<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::Error) -> E,
{
fn new(fut: A::Future, f: F) -> Self {
@ -184,7 +184,7 @@ where
impl<A, F, E> Future for MapErrNewServiceFuture<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::Error) -> E + Clone,
{
type Output = Result<MapErr<A::Service, F, E>, A::InitError>;

View File

@ -5,7 +5,7 @@ use std::task::{Context, Poll};
use pin_project::pin_project;
use super::Factory;
use super::ServiceFactory;
/// `MapInitErr` service combinator
pub(crate) struct MapInitErr<A, F, E> {
@ -16,7 +16,7 @@ pub(crate) struct MapInitErr<A, F, E> {
impl<A, F, E> MapInitErr<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::InitError) -> E,
{
/// Create new `MapInitErr` combinator
@ -43,9 +43,9 @@ where
}
}
impl<A, F, E> Factory for MapInitErr<A, F, E>
impl<A, F, E> ServiceFactory for MapInitErr<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::InitError) -> E + Clone,
{
type Request = A::Request;
@ -64,7 +64,7 @@ where
#[pin_project]
pub(crate) struct MapInitErrFuture<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::InitError) -> E,
{
f: F,
@ -74,7 +74,7 @@ where
impl<A, F, E> MapInitErrFuture<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::InitError) -> E,
{
fn new(fut: A::Future, f: F) -> Self {
@ -84,7 +84,7 @@ where
impl<A, F, E> Future for MapInitErrFuture<A, F, E>
where
A: Factory,
A: ServiceFactory,
F: Fn(A::InitError) -> E,
{
type Output = Result<A::Service, E>;

View File

@ -2,7 +2,7 @@ use std::task::{Context, Poll};
use crate::and_then::{AndThen, AndThenNewService};
use crate::then::{Then, ThenNewService};
use crate::{Factory, IntoFactory, IntoService, Service};
use crate::{IntoService, IntoServiceFactory, Service, ServiceFactory};
pub fn pipeline<F, T>(service: F) -> Pipeline<T>
where
@ -16,8 +16,8 @@ where
pub fn pipeline_factory<T, F>(factory: F) -> PipelineFactory<T>
where
T: Factory,
F: IntoFactory<T>,
T: ServiceFactory,
F: IntoServiceFactory<T>,
{
PipelineFactory {
factory: factory.into_factory(),
@ -106,13 +106,13 @@ pub struct PipelineFactory<T> {
factory: T,
}
impl<T: Factory> PipelineFactory<T> {
impl<T: ServiceFactory> PipelineFactory<T> {
/// Call another service after call to this one has resolved successfully.
pub fn and_then<F, U>(
self,
factory: U,
) -> PipelineFactory<
impl Factory<
impl ServiceFactory<
Config = T::Config,
Request = T::Request,
Response = U::Response,
@ -122,8 +122,8 @@ impl<T: Factory> PipelineFactory<T> {
>
where
Self: Sized,
F: IntoFactory<U>,
U: Factory<
F: IntoServiceFactory<U>,
U: ServiceFactory<
Config = T::Config,
Request = T::Response,
Error = T::Error,
@ -145,7 +145,7 @@ impl<T: Factory> PipelineFactory<T> {
self,
factory: F,
) -> PipelineFactory<
impl Factory<
impl ServiceFactory<
Config = T::Config,
Request = T::Request,
Response = U::Response,
@ -155,8 +155,8 @@ impl<T: Factory> PipelineFactory<T> {
>
where
Self: Sized,
F: IntoFactory<U>,
U: Factory<
F: IntoServiceFactory<U>,
U: ServiceFactory<
Config = T::Config,
Request = Result<T::Response, T::Error>,
Error = T::Error,
@ -180,7 +180,7 @@ where
}
}
impl<T: Factory> Factory for PipelineFactory<T> {
impl<T: ServiceFactory> ServiceFactory for PipelineFactory<T> {
type Config = T::Config;
type Request = T::Request;
type Response = T::Response;

View File

@ -4,7 +4,7 @@ use std::task::{Context, Poll};
use pin_project::pin_project;
use super::{Factory, Service};
use super::{Service, ServiceFactory};
use crate::cell::Cell;
/// Service for the `then` combinator, chaining a computation onto the end of
@ -134,8 +134,8 @@ pub(crate) struct ThenNewService<A, B> {
impl<A, B> ThenNewService<A, B>
where
A: Factory,
B: Factory<
A: ServiceFactory,
B: ServiceFactory<
Config = A::Config,
Request = Result<A::Response, A::Error>,
Error = A::Error,
@ -148,10 +148,10 @@ where
}
}
impl<A, B> Factory for ThenNewService<A, B>
impl<A, B> ServiceFactory for ThenNewService<A, B>
where
A: Factory,
B: Factory<
A: ServiceFactory,
B: ServiceFactory<
Config = A::Config,
Request = Result<A::Response, A::Error>,
Error = A::Error,
@ -188,8 +188,8 @@ where
#[pin_project]
pub(crate) struct ThenNewServiceFuture<A, B>
where
A: Factory,
B: Factory<
A: ServiceFactory,
B: ServiceFactory<
Config = A::Config,
Request = Result<A::Response, A::Error>,
Error = A::Error,
@ -206,8 +206,8 @@ where
impl<A, B> ThenNewServiceFuture<A, B>
where
A: Factory,
B: Factory<
A: ServiceFactory,
B: ServiceFactory<
Config = A::Config,
Request = Result<A::Response, A::Error>,
Error = A::Error,
@ -226,8 +226,8 @@ where
impl<A, B> Future for ThenNewServiceFuture<A, B>
where
A: Factory,
B: Factory<
A: ServiceFactory,
B: ServiceFactory<
Config = A::Config,
Request = Result<A::Response, A::Error>,
Error = A::Error,
@ -267,7 +267,7 @@ mod tests {
use futures::future::{err, ok, ready, Ready};
use crate::{pipeline, pipeline_factory, Factory, Service};
use crate::{pipeline, pipeline_factory, Service, ServiceFactory};
#[derive(Clone)]
struct Srv1(Rc<Cell<usize>>);

View File

@ -5,7 +5,7 @@ use std::sync::Arc;
use std::task::{Context, Poll};
use crate::transform_err::{TransformFromErr, TransformMapInitErr};
use crate::{Factory, IntoFactory, Service};
use crate::{IntoServiceFactory, Service, ServiceFactory};
use pin_project::pin_project;
@ -133,7 +133,7 @@ where
pub fn apply_transform<T, S, F, U>(
t: F,
service: U,
) -> impl Factory<
) -> impl ServiceFactory<
Config = S::Config,
Request = T::Request,
Response = T::Response,
@ -142,10 +142,10 @@ pub fn apply_transform<T, S, F, U>(
InitError = S::InitError,
> + Clone
where
S: Factory,
S: ServiceFactory,
T: Transform<S::Service, InitError = S::InitError>,
F: IntoTransform<T, S::Service>,
U: IntoFactory<S>,
U: IntoServiceFactory<S>,
{
ApplyTransform::new(t.into_transform(), service.into_factory())
}
@ -158,7 +158,7 @@ pub struct ApplyTransform<T, S> {
impl<T, S> ApplyTransform<T, S>
where
S: Factory,
S: ServiceFactory,
T: Transform<S::Service, InitError = S::InitError>,
{
/// Create new `ApplyTransform` new service instance
@ -179,9 +179,9 @@ impl<T, S> Clone for ApplyTransform<T, S> {
}
}
impl<T, S> Factory for ApplyTransform<T, S>
impl<T, S> ServiceFactory for ApplyTransform<T, S>
where
S: Factory,
S: ServiceFactory,
T: Transform<S::Service, InitError = S::InitError>,
{
type Request = T::Request;
@ -204,7 +204,7 @@ where
#[pin_project]
pub struct ApplyTransformFuture<T, S>
where
S: Factory,
S: ServiceFactory,
T: Transform<S::Service, InitError = S::InitError>,
{
#[pin]
@ -216,7 +216,7 @@ where
impl<T, S> Future for ApplyTransformFuture<T, S>
where
S: Factory,
S: ServiceFactory,
T: Transform<S::Service, InitError = S::InitError>,
{
type Output = Result<T::Transform, T::InitError>;