Trait actix_web::dev::ServiceFactory

pub trait ServiceFactory<Req> {
    type Response;
    type Error;
    type Config;
    type Service: Service<Req, Response = Self::Response, Error = Self::Error>;
    type InitError;
    type Future: Future<Output = Result<Self::Service, Self::InitError>>;

    // Required method
    fn new_service(&self, cfg: Self::Config) -> Self::Future;
}
Expand description

Factory for creating Services.

This is useful for cases where new Services must be produced. One case is a TCP server listener: a listener accepts new connections, constructs a new Service for each using the ServiceFactory trait, and uses the new Service to process inbound requests on that new connection.

Config is a service factory configuration type.

Simple factories may be able to use fn_factory or [fn_factory_with_config] to reduce boilerplate.

Required Associated Types§

type Response

Responses given by the created services.

type Error

Errors produced by the created services.

type Config

Service factory configuration.

type Service: Service<Req, Response = Self::Response, Error = Self::Error>

The kind of Service created by this factory.

type InitError

Errors potentially raised while building a service.

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

The future of the Service instance.g

Required Methods§

fn new_service(&self, cfg: Self::Config) -> Self::Future

Create and return a new service asynchronously.

Implementations on Foreign Types§

source§

impl ServiceFactory<Request> for ExpectHandler

§

impl<IO> ServiceFactory<IO> for Acceptor
where IO: ActixStream,

§

type Response = TlsStream<IO>

§

type Error = TlsError<Error, Infallible>

§

type Config = ()

§

type Service = AcceptorService

§

type InitError = ()

§

type Future = Ready<Result<<Acceptor as ServiceFactory<IO>>::Service, <Acceptor as ServiceFactory<IO>>::InitError>>

§

fn new_service(&self, _: ()) -> <Acceptor as ServiceFactory<IO>>::Future

§

impl<IO> ServiceFactory<IO> for Acceptor
where IO: ActixStream,

§

type Response = TlsStream<IO>

§

type Error = TlsError<Error, Infallible>

§

type Config = ()

§

type Service = AcceptorService

§

type InitError = ()

§

type Future = Ready<Result<<Acceptor as ServiceFactory<IO>>::Service, <Acceptor as ServiceFactory<IO>>::InitError>>

§

fn new_service(&self, _: ()) -> <Acceptor as ServiceFactory<IO>>::Future

§

impl<IO> ServiceFactory<IO> for Acceptor
where IO: ActixStream,

§

type Response = TlsStream<IO>

§

type Error = TlsError<Error, Infallible>

§

type Config = ()

§

type Service = AcceptorService

§

type InitError = ()

§

type Future = Ready<Result<<Acceptor as ServiceFactory<IO>>::Service, <Acceptor as ServiceFactory<IO>>::InitError>>

§

fn new_service(&self, _: ()) -> <Acceptor as ServiceFactory<IO>>::Future

§

impl<IO> ServiceFactory<IO> for Acceptor
where IO: ActixStream,

§

type Response = TlsStream<IO>

§

type Error = TlsError<Error, Infallible>

§

type Config = ()

§

type Service = AcceptorService

§

type InitError = ()

§

type Future = Ready<Result<<Acceptor as ServiceFactory<IO>>::Service, <Acceptor as ServiceFactory<IO>>::InitError>>

§

fn new_service(&self, _: ()) -> <Acceptor as ServiceFactory<IO>>::Future

§

impl<IO> ServiceFactory<IO> for Acceptor
where IO: ActixStream,

§

type Response = TlsStream<IO>

§

type Error = TlsError<Error, Infallible>

§

type Config = ()

§

type Service = AcceptorService

§

type InitError = ()

§

type Future = Ready<Result<<Acceptor as ServiceFactory<IO>>::Service, <Acceptor as ServiceFactory<IO>>::InitError>>

§

fn new_service(&self, _: ()) -> <Acceptor as ServiceFactory<IO>>::Future

§

impl<R> ServiceFactory<ConnectInfo<R>> for Connector
where R: Host,

§

type Response = Connection<R, TcpStream>

§

type Error = ConnectError

§

type Config = ()

§

type Service = ConnectorService

§

type InitError = ()

§

type Future = Ready<Result<<Connector as ServiceFactory<ConnectInfo<R>>>::Service, <Connector as ServiceFactory<ConnectInfo<R>>>::InitError>>

§

fn new_service( &self, _: () ) -> <Connector as ServiceFactory<ConnectInfo<R>>>::Future

§

impl<R> ServiceFactory<ConnectInfo<R>> for Resolver
where R: Host,

§

type Response = ConnectInfo<R>

§

type Error = ConnectError

§

type Config = ()

§

type Service = ResolverService

§

type InitError = ()

§

type Future = Ready<Result<<Resolver as ServiceFactory<ConnectInfo<R>>>::Service, <Resolver as ServiceFactory<ConnectInfo<R>>>::InitError>>

§

fn new_service( &self, _: () ) -> <Resolver as ServiceFactory<ConnectInfo<R>>>::Future

§

impl<R> ServiceFactory<ConnectInfo<R>> for TcpConnector
where R: Host,

§

type Response = Connection<R, TcpStream>

§

type Error = ConnectError

§

type Config = ()

§

type Service = TcpConnectorService

§

type InitError = ()

§

type Future = Ready<Result<<TcpConnector as ServiceFactory<ConnectInfo<R>>>::Service, <TcpConnector as ServiceFactory<ConnectInfo<R>>>::InitError>>

§

fn new_service( &self, _: () ) -> <TcpConnector as ServiceFactory<ConnectInfo<R>>>::Future

§

impl<R, IO> ServiceFactory<Connection<R, IO>> for TlsConnector
where R: Host, IO: ActixStream + 'static,

§

type Response = Connection<R, TlsStream<IO>>

§

type Error = Error

§

type Config = ()

§

type Service = TlsConnectorService

§

type InitError = ()

§

type Future = Ready<Result<<TlsConnector as ServiceFactory<Connection<R, IO>>>::Service, <TlsConnector as ServiceFactory<Connection<R, IO>>>::InitError>>

§

fn new_service( &self, _: () ) -> <TlsConnector as ServiceFactory<Connection<R, IO>>>::Future

§

impl<R, IO> ServiceFactory<Connection<R, IO>> for TlsConnector
where R: Host, IO: ActixStream + 'static,

§

type Response = Connection<R, SslStream<IO>>

§

type Error = Error

§

type Config = ()

§

type Service = TlsConnectorService

§

type InitError = ()

§

type Future = Ready<Result<<TlsConnector as ServiceFactory<Connection<R, IO>>>::Service, <TlsConnector as ServiceFactory<Connection<R, IO>>>::InitError>>

§

fn new_service( &self, _: () ) -> <TlsConnector as ServiceFactory<Connection<R, IO>>>::Future

§

impl<R, IO> ServiceFactory<Connection<R, IO>> for TlsConnector
where R: Host, IO: ActixStream + 'static,

§

type Response = Connection<R, TlsStream<IO>>

§

type Error = Error

§

type Config = ()

§

type Service = TlsConnectorService

§

type InitError = ()

§

type Future = Ready<Result<<TlsConnector as ServiceFactory<Connection<R, IO>>>::Service, <TlsConnector as ServiceFactory<Connection<R, IO>>>::InitError>>

§

fn new_service( &self, _: () ) -> <TlsConnector as ServiceFactory<Connection<R, IO>>>::Future

§

impl<R, IO> ServiceFactory<Connection<R, IO>> for TlsConnector
where R: Host, IO: ActixStream + 'static,

§

type Response = Connection<R, TlsStream<IO>>

§

type Error = Error

§

type Config = ()

§

type Service = TlsConnectorService

§

type InitError = ()

§

type Future = Ready<Result<<TlsConnector as ServiceFactory<Connection<R, IO>>>::Service, <TlsConnector as ServiceFactory<Connection<R, IO>>>::InitError>>

§

fn new_service( &self, _: () ) -> <TlsConnector as ServiceFactory<Connection<R, IO>>>::Future

§

impl<R, IO> ServiceFactory<Connection<R, IO>> for TlsConnector
where R: Host, IO: ActixStream + 'static,

§

type Response = Connection<R, TlsStream<IO>>

§

type Error = Error

§

type Config = ()

§

type Service = TlsConnectorService

§

type InitError = ()

§

type Future = Ready<Result<<TlsConnector as ServiceFactory<Connection<R, IO>>>::Service, <TlsConnector as ServiceFactory<Connection<R, IO>>>::InitError>>

§

fn new_service( &self, _: () ) -> <TlsConnector as ServiceFactory<Connection<R, IO>>>::Future

§

impl<S, Req> ServiceFactory<Req> for Rc<S>
where S: ServiceFactory<Req>,

§

type Response = <S as ServiceFactory<Req>>::Response

§

type Error = <S as ServiceFactory<Req>>::Error

§

type Config = <S as ServiceFactory<Req>>::Config

§

type Service = <S as ServiceFactory<Req>>::Service

§

type InitError = <S as ServiceFactory<Req>>::InitError

§

type Future = <S as ServiceFactory<Req>>::Future

§

fn new_service( &self, cfg: <S as ServiceFactory<Req>>::Config ) -> <S as ServiceFactory<Req>>::Future

§

impl<S, Req> ServiceFactory<Req> for Arc<S>
where S: ServiceFactory<Req>,

§

type Response = <S as ServiceFactory<Req>>::Response

§

type Error = <S as ServiceFactory<Req>>::Error

§

type Config = <S as ServiceFactory<Req>>::Config

§

type Service = <S as ServiceFactory<Req>>::Service

§

type InitError = <S as ServiceFactory<Req>>::InitError

§

type Future = <S as ServiceFactory<Req>>::Future

§

fn new_service( &self, cfg: <S as ServiceFactory<Req>>::Config ) -> <S as ServiceFactory<Req>>::Future

source§

impl<T> ServiceFactory<(Request, Framed<T, Codec>)> for UpgradeHandler

source§

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

§

type Response = ()

§

type Error = DispatchError

§

type Config = ()

§

type Service = H2ServiceHandler<T, <S as ServiceFactory<Request>>::Service, B>

§

type InitError = <S as ServiceFactory<Request>>::InitError

§

type Future = Pin<Box<dyn Future<Output = Result<<H2Service<T, S, B> as ServiceFactory<(T, Option<SocketAddr>)>>::Service, <H2Service<T, S, B> as ServiceFactory<(T, Option<SocketAddr>)>>::InitError>>>>

source§

fn new_service( &self, _: () ) -> <H2Service<T, S, B> as ServiceFactory<(T, Option<SocketAddr>)>>::Future

source§

impl<T, S, B, X, U> ServiceFactory<(T, Protocol, Option<SocketAddr>)> for HttpService<T, S, B, X, U>
where T: AsyncRead + AsyncWrite + Unpin + 'static, S: ServiceFactory<Request, Config = ()>, <S as ServiceFactory<Request>>::Future: 'static, <S as ServiceFactory<Request>>::Error: Into<Response<BoxBody>> + 'static, <S as ServiceFactory<Request>>::InitError: Debug, <S as ServiceFactory<Request>>::Response: Into<Response<B>> + 'static, <<S as ServiceFactory<Request>>::Service as Service<Request>>::Future: 'static, B: MessageBody + 'static, X: ServiceFactory<Request, Config = (), Response = Request>, <X as ServiceFactory<Request>>::Future: 'static, <X as ServiceFactory<Request>>::Error: Into<Response<BoxBody>>, <X as ServiceFactory<Request>>::InitError: Debug, U: ServiceFactory<(Request, Framed<T, Codec>), Config = (), Response = ()>, <U as ServiceFactory<(Request, Framed<T, Codec>)>>::Future: 'static, <U as ServiceFactory<(Request, Framed<T, Codec>)>>::Error: Display + Into<Response<BoxBody>>, <U as ServiceFactory<(Request, Framed<T, Codec>)>>::InitError: Debug,

§

type Response = ()

§

type Error = DispatchError

§

type Config = ()

§

type Service = HttpServiceHandler<T, <S as ServiceFactory<Request>>::Service, B, <X as ServiceFactory<Request>>::Service, <U as ServiceFactory<(Request, Framed<T, Codec>)>>::Service>

§

type InitError = ()

§

type Future = Pin<Box<dyn Future<Output = Result<<HttpService<T, S, B, X, U> as ServiceFactory<(T, Protocol, Option<SocketAddr>)>>::Service, <HttpService<T, S, B, X, U> as ServiceFactory<(T, Protocol, Option<SocketAddr>)>>::InitError>>>>

source§

fn new_service( &self, _: () ) -> <HttpService<T, S, B, X, U> as ServiceFactory<(T, Protocol, Option<SocketAddr>)>>::Future

source§

impl<T, S, B, X, U> ServiceFactory<(T, Option<SocketAddr>)> for H1Service<T, S, B, X, U>
where T: AsyncRead + AsyncWrite + Unpin + 'static, S: ServiceFactory<Request, Config = ()>, <S as ServiceFactory<Request>>::Future: 'static, <S as ServiceFactory<Request>>::Error: Into<Response<BoxBody>>, <S as ServiceFactory<Request>>::Response: Into<Response<B>>, <S as ServiceFactory<Request>>::InitError: Debug, B: MessageBody, X: ServiceFactory<Request, Config = (), Response = Request>, <X as ServiceFactory<Request>>::Future: 'static, <X as ServiceFactory<Request>>::Error: Into<Response<BoxBody>>, <X as ServiceFactory<Request>>::InitError: Debug, U: ServiceFactory<(Request, Framed<T, Codec>), Config = (), Response = ()>, <U as ServiceFactory<(Request, Framed<T, Codec>)>>::Future: 'static, <U as ServiceFactory<(Request, Framed<T, Codec>)>>::Error: Display + Into<Response<BoxBody>>, <U as ServiceFactory<(Request, Framed<T, Codec>)>>::InitError: Debug,

§

type Response = ()

§

type Error = DispatchError

§

type Config = ()

§

type Service = HttpServiceHandler<T, <S as ServiceFactory<Request>>::Service, B, <X as ServiceFactory<Request>>::Service, <U as ServiceFactory<(Request, Framed<T, Codec>)>>::Service>

§

type InitError = ()

§

type Future = Pin<Box<dyn Future<Output = Result<<H1Service<T, S, B, X, U> as ServiceFactory<(T, Option<SocketAddr>)>>::Service, <H1Service<T, S, B, X, U> as ServiceFactory<(T, Option<SocketAddr>)>>::InitError>>>>

source§

fn new_service( &self, _: () ) -> <H1Service<T, S, B, X, U> as ServiceFactory<(T, Option<SocketAddr>)>>::Future

Implementors§

source§

impl ServiceFactory<ServiceRequest> for Route

§

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

§

type Response = Res

§

type Error = Err

§

type Config = C

§

type Service = Box<dyn Service<Req, Future = Pin<Box<dyn Future<Output = Result<Res, Err>>>>, Response = Res, Error = Err>>

§

type InitError = InitErr

§

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

§

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

§

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

§

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

§

type Config = <S as ServiceFactory<Req>>::Config

§

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

§

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

§

type Future = ApplyTransformFuture<T, S, Req>