Trait ntex::service::ServiceFactory[][src]

pub trait ServiceFactory {
    type Request;
    type Response;
    type Error;
    type Config;
    type Service: Service;
    type InitError;
    type Future: Future;
    pub fn new_service(&self, cfg: Self::Config) -> Self::Future;

    pub fn map<F, R>(self, f: F) -> MapServiceFactory<Self, F, R>
    where
        F: FnMut(Self::Response) -> R + Clone
, { ... }
pub fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, F, E>
    where
        F: Fn(Self::Error) -> E + Clone
, { ... }
pub fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E>
    where
        F: Fn(Self::InitError) -> E + Clone
, { ... } }

Creates new Service values.

Acts as a service factory. This is useful for cases where new Service values must be produced. One case is a TCP server listener. The listener accepts new TCP streams, obtains a new Service value using the ServiceFactory trait, and uses that new Service value to process inbound requests on that new TCP stream.

Config is a service factory configuration type.

Associated Types

type Request[src]

Requests handled by the service.

type Response[src]

Responses given by the service

type Error[src]

Errors produced by the service

type Config[src]

Service factory configuration

type Service: Service[src]

The Service value created by this factory

type InitError[src]

Errors produced while building a service.

type Future: Future[src]

The future of the ServiceFactory instance.

Loading content...

Required methods

pub fn new_service(&self, cfg: Self::Config) -> Self::Future[src]

Create and return a new service value asynchronously.

Loading content...

Provided methods

pub fn map<F, R>(self, f: F) -> MapServiceFactory<Self, F, R> where
    F: FnMut(Self::Response) -> R + Clone
[src]

Map this service's output to a different type, returning a new service of the resulting type.

pub fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, F, E> where
    F: Fn(Self::Error) -> E + Clone
[src]

Map this service's error to a different error, returning a new service.

pub fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E> where
    F: Fn(Self::InitError) -> E + Clone
[src]

Map this factory's init error to a different error, returning a new service.

Loading content...

Implementations on Foreign Types

impl<S> ServiceFactory for Rc<S> where
    S: ServiceFactory
[src]

type Request = <S as ServiceFactory>::Request

type Response = <S as ServiceFactory>::Response

type Error = <S as ServiceFactory>::Error

type Config = <S as ServiceFactory>::Config

type Service = <S as ServiceFactory>::Service

type InitError = <S as ServiceFactory>::InitError

type Future = <S as ServiceFactory>::Future

Loading content...

Implementors

impl ServiceFactory for ExpectHandler[src]

type Config = ()

type Request = Request

type Response = Request

type Error = Error

type Service = ExpectHandler

type InitError = Error

type Future = Ready<Result<Self::Service, Self::InitError>>

impl ServiceFactory for LowResTime[src]

type Request = ()

type Response = Instant

type Error = Infallible

type InitError = Infallible

type Config = ()

type Service = LowResTimeService

type Future = Ready<Result<Self::Service, Self::InitError>>

impl<A, C> ServiceFactory for UnitConfig<A, C> where
    A: ServiceFactory<Config = ()>, 
[src]

impl<A, F, C> ServiceFactory for MapConfig<A, F, C> where
    F: Fn(C) -> <A as ServiceFactory>::Config,
    A: ServiceFactory
[src]

type Request = <A as ServiceFactory>::Request

type Response = <A as ServiceFactory>::Response

type Error = <A as ServiceFactory>::Error

type Config = C

type Service = <A as ServiceFactory>::Service

type InitError = <A as ServiceFactory>::InitError

type Future = <A as ServiceFactory>::Future

impl<A, F, E> ServiceFactory for MapErrServiceFactory<A, F, E> where
    F: Fn(<A as ServiceFactory>::Error) -> E + Clone,
    A: ServiceFactory
[src]

type Request = <A as ServiceFactory>::Request

type Response = <A as ServiceFactory>::Response

type Error = E

type Config = <A as ServiceFactory>::Config

type Service = MapErr<<A as ServiceFactory>::Service, F, E>

type InitError = <A as ServiceFactory>::InitError

type Future = MapErrServiceFuture<A, F, E>

impl<A, F, E> ServiceFactory for MapInitErr<A, F, E> where
    F: Fn(<A as ServiceFactory>::InitError) -> E + Clone,
    A: ServiceFactory
[src]

type Request = <A as ServiceFactory>::Request

type Response = <A as ServiceFactory>::Response

type Error = <A as ServiceFactory>::Error

type Config = <A as ServiceFactory>::Config

type Service = <A as ServiceFactory>::Service

type InitError = E

type Future = MapInitErrFuture<A, F, E>

impl<A, F, Res> ServiceFactory for MapServiceFactory<A, F, Res> where
    F: FnMut(<A as ServiceFactory>::Response) -> Res + Clone,
    A: ServiceFactory
[src]

type Request = <A as ServiceFactory>::Request

type Response = Res

type Error = <A as ServiceFactory>::Error

type Config = <A as ServiceFactory>::Config

type Service = Map<<A as ServiceFactory>::Service, F, Res>

type InitError = <A as ServiceFactory>::InitError

type Future = MapServiceFuture<A, F, Res>

impl<C, Req, Res, Err, InitErr> ServiceFactory for BoxServiceFactory<C, Req, Res, Err, InitErr> where
    Err: 'static,
    Res: 'static,
    Req: 'static,
    InitErr: 'static, 
[src]

type Request = Req

type Response = Res

type Error = Err

type InitError = InitErr

type Config = C

type Service = Box<dyn Service<Error = Err, Future = Pin<Box<dyn Future<Output = Result<Res, Err>> + 'static, Global>>, Response = Res, Request = Req> + 'static, Global>

type Future = Pin<Box<dyn Future<Output = Result<<BoxServiceFactory<C, Req, Res, Err, InitErr> as ServiceFactory>::Service, InitErr>> + 'static, Global>>

impl<Err: ErrorRenderer> ServiceFactory for Route<Err>[src]

type Config = ()

type Request = WebRequest<Err>

type Response = WebResponse

type Error = Err::Container

type InitError = ()

type Service = RouteService<Err>

type Future = Ready<Result<RouteService<Err>, ()>>

impl<F, C, S, R, E> ServiceFactory for FnServiceNoConfig<F, C, S, R, E> where
    S: Service,
    F: Fn() -> R,
    R: Future<Output = Result<S, E>>, 
[src]

type Request = <S as Service>::Request

type Response = <S as Service>::Response

type Error = <S as Service>::Error

type Service = S

type Config = C

type InitError = E

type Future = R

impl<F, Fut, Cfg, Srv, Err> ServiceFactory for FnServiceConfig<F, Fut, Cfg, Srv, Err> where
    F: Fn(Cfg) -> Fut,
    Fut: Future<Output = Result<Srv, Err>>,
    Srv: Service
[src]

type Request = <Srv as Service>::Request

type Response = <Srv as Service>::Response

type Error = <Srv as Service>::Error

type Config = Cfg

type Service = Srv

type InitError = Err

type Future = Fut

impl<F, Fut, Req, Res, Err, Cfg> ServiceFactory for FnServiceFactory<F, Fut, Req, Res, Err, Cfg> where
    F: Fn(Req) -> Fut + Clone,
    Fut: Future<Output = Result<Res, Err>>, 
[src]

type Request = Req

type Response = Res

type Error = Err

type Config = Cfg

type Service = FnService<F, Fut, Req, Res, Err>

type InitError = ()

type Future = Ready<Result<<FnServiceFactory<F, Fut, Req, Res, Err, Cfg> as ServiceFactory>::Service, <FnServiceFactory<F, Fut, Req, Res, Err, Cfg> as ServiceFactory>::InitError>>

impl<R, E, F> ServiceFactory for KeepAlive<R, E, F> where
    F: Fn() -> E + Clone
[src]

type Request = R

type Response = R

type Error = E

type InitError = Infallible

type Config = ()

type Service = KeepAliveService<R, E, F>

type Future = Ready<Result<Self::Service, Self::InitError>>

impl<T> ServiceFactory for UpgradeHandler<T>[src]

type Config = ()

type Request = (Request, T, State, Codec)

type Response = ()

type Error = Error

type Service = UpgradeHandler<T>

type InitError = Error

type Future = Ready<Result<Self::Service, Self::InitError>>

impl<T> ServiceFactory for ntex::server::openssl::Acceptor<T> where
    T: AsyncRead + AsyncWrite + Unpin + Debug + 'static, 
[src]

type Request = T

type Response = SslStream<T>

type Error = Box<dyn Error>

type Config = ()

type Service = AcceptorService<T>

type InitError = ()

type Future = Ready<Result<Self::Service, Self::InitError>>

impl<T> ServiceFactory for PipelineFactory<T> where
    T: ServiceFactory
[src]

type Config = <T as ServiceFactory>::Config

type Request = <T as ServiceFactory>::Request

type Response = <T as ServiceFactory>::Response

type Error = <T as ServiceFactory>::Error

type Service = <T as ServiceFactory>::Service

type InitError = <T as ServiceFactory>::InitError

type Future = <T as ServiceFactory>::Future

impl<T, F, R, In, Out, Err> ServiceFactory for ApplyServiceFactory<T, F, R, In, Out, Err> where
    T: ServiceFactory<Error = Err>,
    F: Fn(In, &<T as ServiceFactory>::Service) -> R + Clone,
    R: Future<Output = Result<Out, Err>>, 
[src]

type Request = In

type Response = Out

type Error = Err

type Config = <T as ServiceFactory>::Config

type Service = Apply<<T as ServiceFactory>::Service, F, R, In, Out, Err>

type InitError = <T as ServiceFactory>::InitError

type Future = ApplyServiceFactoryResponse<T, F, R, In, Out, Err>

impl<T, S> ServiceFactory for ApplyTransform<T, S> where
    T: Transform<<S as ServiceFactory>::Service, InitError = <S as ServiceFactory>::InitError>,
    S: ServiceFactory
[src]

type Request = <T as Transform<<S as ServiceFactory>::Service>>::Request

type Response = <T as Transform<<S as ServiceFactory>::Service>>::Response

type Error = <T as Transform<<S as ServiceFactory>::Service>>::Error

type Config = <S as ServiceFactory>::Config

type Service = <T as Transform<<S as ServiceFactory>::Service>>::Transform

type InitError = <T as Transform<<S as ServiceFactory>::Service>>::InitError

type Future = ApplyTransformFuture<T, S>

impl<T, S, B> ServiceFactory for H2Service<T, S, B> where
    T: AsyncRead + AsyncWrite + Unpin + 'static,
    S: ServiceFactory<Config = (), Request = Request>,
    S::Error: ResponseError + 'static,
    S::Response: Into<Response<B>> + 'static,
    S::Future: 'static,
    <S::Service as Service>::Future: 'static,
    B: MessageBody + 'static, 
[src]

type Config = ()

type Request = (T, Option<SocketAddr>)

type Response = ()

type Error = DispatchError

type InitError = S::InitError

type Service = H2ServiceHandler<T, S::Service, B>

type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>

impl<T, S, B, X, U> ServiceFactory for H1Service<T, S, B, X, U> where
    T: AsyncRead + AsyncWrite + Unpin + 'static,
    S: ServiceFactory<Config = (), Request = Request>,
    S::Error: ResponseError + 'static,
    S::Response: Into<Response<B>>,
    S::InitError: Debug,
    S::Future: 'static,
    B: MessageBody,
    X: ServiceFactory<Config = (), Request = Request, Response = Request>,
    X::Error: ResponseError + 'static,
    X::InitError: Debug,
    X::Future: 'static,
    U: ServiceFactory<Config = (), Request = (Request, T, IoState, Codec), Response = ()>,
    U::Error: Display + Error + 'static,
    U::InitError: Debug,
    U::Future: 'static, 
[src]

type Config = ()

type Request = (T, Option<SocketAddr>)

type Response = ()

type Error = DispatchError

type InitError = ()

type Service = H1ServiceHandler<T, S::Service, B, X::Service, U::Service>

type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>

impl<T, S, B, X, U> ServiceFactory for HttpService<T, S, B, X, U> where
    T: AsyncRead + AsyncWrite + Unpin + 'static,
    S: ServiceFactory<Config = (), Request = Request>,
    S::Error: ResponseError + 'static,
    S::InitError: Debug,
    S::Future: 'static,
    S::Response: Into<Response<B>> + 'static,
    <S::Service as Service>::Future: 'static,
    B: MessageBody + 'static,
    X: ServiceFactory<Config = (), Request = Request, Response = Request>,
    X::Error: ResponseError + 'static,
    X::InitError: Debug,
    X::Future: 'static,
    <X::Service as Service>::Future: 'static,
    U: ServiceFactory<Config = (), Request = (Request, T, State, Codec), Response = ()>,
    U::Error: Display + Error + 'static,
    U::InitError: Debug,
    U::Future: 'static,
    <U::Service as Service>::Future: 'static, 
[src]

type Config = ()

type Request = (T, Protocol, Option<SocketAddr>)

type Response = ()

type Error = DispatchError

type InitError = ()

type Service = HttpServiceHandler<T, S::Service, B, X::Service, U::Service>

type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>

impl<T: AsyncRead + AsyncWrite + Unpin> ServiceFactory for ntex::server::rustls::Acceptor<T>[src]

type Request = T

type Response = TlsStream<T>

type Error = Box<dyn Error>

type Service = AcceptorService<T>

type Config = ()

type InitError = ()

type Future = Ready<Result<Self::Service, Self::InitError>>

impl<T: Address + 'static> ServiceFactory for OpensslConnector<T>[src]

type Request = Connect<T>

type Response = SslStream<TcpStream>

type Error = ConnectError

type Config = ()

type Service = OpensslConnector<T>

type InitError = ()

type Future = Ready<Result<Self::Service, Self::InitError>>

impl<T: Address + 'static> ServiceFactory for RustlsConnector<T>[src]

type Request = Connect<T>

type Response = TlsStream<TcpStream>

type Error = ConnectError

type Config = ()

type Service = RustlsConnector<T>

type InitError = ()

type Future = Ready<Result<Self::Service, Self::InitError>>

impl<T: Address> ServiceFactory for Connector<T>[src]

type Request = Connect<T>

type Response = TcpStream

type Error = ConnectError

type Config = ()

type Service = Connector<T>

type InitError = ()

type Future = Ready<Result<Self::Service, Self::InitError>>

impl<T: Address> ServiceFactory for Resolver<T>[src]

type Request = Connect<T>

type Response = Connect<T>

type Error = ConnectError

type Config = ()

type Service = Resolver<T>

type InitError = ()

type Future = Ready<Result<Self::Service, Self::InitError>>

impl<V1, V2> ServiceFactory for VariantFactory2<V1, V2> where
    V1: ServiceFactory,
    V1::Config: Clone,
    V2: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>, 
[src]

type Request = Variant2<V1::Request, V2::Request>

type Response = V1::Response

type Error = V1::Error

type Config = V1::Config

type InitError = V1::InitError

type Service = VariantService2<V1::Service, V2::Service>

type Future = ServiceFactoryResponse<V1, V2>

impl<V1, V2, V3> ServiceFactory for VariantFactory3<V1, V2, V3> where
    V1: ServiceFactory,
    V1::Config: Clone,
    V2: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V3: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>, 
[src]

type Request = Variant3<V1::Request, V2::Request, V3::Request>

type Response = V1::Response

type Error = V1::Error

type Config = V1::Config

type InitError = V1::InitError

type Service = VariantService3<V1::Service, V2::Service, V3::Service>

type Future = ServiceFactoryResponse<V1, V2, V3>

impl<V1, V2, V3, V4> ServiceFactory for VariantFactory4<V1, V2, V3, V4> where
    V1: ServiceFactory,
    V1::Config: Clone,
    V2: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V3: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V4: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>, 
[src]

type Request = Variant4<V1::Request, V2::Request, V3::Request, V4::Request>

type Response = V1::Response

type Error = V1::Error

type Config = V1::Config

type InitError = V1::InitError

type Service = VariantService4<V1::Service, V2::Service, V3::Service, V4::Service>

type Future = ServiceFactoryResponse<V1, V2, V3, V4>

impl<V1, V2, V3, V4, V5> ServiceFactory for VariantFactory5<V1, V2, V3, V4, V5> where
    V1: ServiceFactory,
    V1::Config: Clone,
    V2: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V3: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V4: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V5: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>, 
[src]

type Request = Variant5<V1::Request, V2::Request, V3::Request, V4::Request, V5::Request>

type Response = V1::Response

type Error = V1::Error

type Config = V1::Config

type InitError = V1::InitError

type Service = VariantService5<V1::Service, V2::Service, V3::Service, V4::Service, V5::Service>

type Future = ServiceFactoryResponse<V1, V2, V3, V4, V5>

impl<V1, V2, V3, V4, V5, V6> ServiceFactory for VariantFactory6<V1, V2, V3, V4, V5, V6> where
    V1: ServiceFactory,
    V1::Config: Clone,
    V2: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V3: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V4: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V5: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V6: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>, 
[src]

type Request = Variant6<V1::Request, V2::Request, V3::Request, V4::Request, V5::Request, V6::Request>

type Response = V1::Response

type Error = V1::Error

type Config = V1::Config

type InitError = V1::InitError

type Service = VariantService6<V1::Service, V2::Service, V3::Service, V4::Service, V5::Service, V6::Service>

type Future = ServiceFactoryResponse<V1, V2, V3, V4, V5, V6>

impl<V1, V2, V3, V4, V5, V6, V7> ServiceFactory for VariantFactory7<V1, V2, V3, V4, V5, V6, V7> where
    V1: ServiceFactory,
    V1::Config: Clone,
    V2: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V3: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V4: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V5: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V6: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V7: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>, 
[src]

type Request = Variant7<V1::Request, V2::Request, V3::Request, V4::Request, V5::Request, V6::Request, V7::Request>

type Response = V1::Response

type Error = V1::Error

type Config = V1::Config

type InitError = V1::InitError

type Service = VariantService7<V1::Service, V2::Service, V3::Service, V4::Service, V5::Service, V6::Service, V7::Service>

type Future = ServiceFactoryResponse<V1, V2, V3, V4, V5, V6, V7>

impl<V1, V2, V3, V4, V5, V6, V7, V8> ServiceFactory for VariantFactory8<V1, V2, V3, V4, V5, V6, V7, V8> where
    V1: ServiceFactory,
    V1::Config: Clone,
    V2: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V3: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V4: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V5: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V6: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V7: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>,
    V8: ServiceFactory<Config = V1::Config, Response = V1::Response, Error = V1::Error, InitError = V1::InitError>, 
[src]

type Request = Variant8<V1::Request, V2::Request, V3::Request, V4::Request, V5::Request, V6::Request, V7::Request, V8::Request>

type Response = V1::Response

type Error = V1::Error

type Config = V1::Config

type InitError = V1::InitError

type Service = VariantService8<V1::Service, V2::Service, V3::Service, V4::Service, V5::Service, V6::Service, V7::Service, V8::Service>

type Future = ServiceFactoryResponse<V1, V2, V3, V4, V5, V6, V7, V8>

Loading content...