1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-28 15:40:36 +02:00

service trait takes request type parameter (#232)

This commit is contained in:
Rob Ede
2020-12-27 04:28:00 +00:00
committed by GitHub
parent 518bf3f6a6
commit 3ab8c3eb69
28 changed files with 1142 additions and 1136 deletions

View File

@ -40,8 +40,7 @@ impl<T> Clone for TcpConnectorFactory<T> {
}
}
impl<T: Address> ServiceFactory for TcpConnectorFactory<T> {
type Request = Connect<T>;
impl<T: Address> ServiceFactory<Connect<T>> for TcpConnectorFactory<T> {
type Response = Connection<T, TcpStream>;
type Error = ConnectError;
type Config = ();
@ -70,8 +69,7 @@ impl<T> Clone for TcpConnector<T> {
}
}
impl<T: Address> Service for TcpConnector<T> {
type Request = Connect<T>;
impl<T: Address> Service<Connect<T>> for TcpConnector<T> {
type Response = Connection<T, TcpStream>;
type Error = ConnectError;
#[allow(clippy::type_complexity)]

View File

@ -76,8 +76,8 @@ pub async fn start_default_resolver() -> Result<AsyncResolver, ConnectError> {
/// Create TCP connector service.
pub fn new_connector<T: Address + 'static>(
resolver: AsyncResolver,
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
+ Clone {
) -> impl Service<Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError> + Clone
{
pipeline(Resolver::new(resolver)).and_then(TcpConnector::new())
}
@ -85,8 +85,8 @@ pub fn new_connector<T: Address + 'static>(
pub fn new_connector_factory<T: Address + 'static>(
resolver: AsyncResolver,
) -> impl ServiceFactory<
Connect<T>,
Config = (),
Request = Connect<T>,
Response = Connection<T, TcpStream>,
Error = ConnectError,
InitError = (),
@ -96,15 +96,15 @@ pub fn new_connector_factory<T: Address + 'static>(
/// Create connector service with default parameters.
pub fn default_connector<T: Address + 'static>(
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
+ Clone {
) -> impl Service<Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError> + Clone
{
pipeline(Resolver::default()).and_then(TcpConnector::new())
}
/// Create connector service factory with default parameters.
pub fn default_connector_factory<T: Address + 'static>() -> impl ServiceFactory<
Connect<T>,
Config = (),
Request = Connect<T>,
Response = Connection<T, TcpStream>,
Error = ConnectError,
InitError = (),

View File

@ -54,8 +54,7 @@ impl<T> Clone for ResolverFactory<T> {
}
}
impl<T: Address> ServiceFactory for ResolverFactory<T> {
type Request = Connect<T>;
impl<T: Address> ServiceFactory<Connect<T>> for ResolverFactory<T> {
type Response = Connect<T>;
type Error = ConnectError;
type Config = ();
@ -102,8 +101,7 @@ impl<T> Clone for Resolver<T> {
}
}
impl<T: Address> Service for Resolver<T> {
type Request = Connect<T>;
impl<T: Address> Service<Connect<T>> for Resolver<T> {
type Response = Connect<T>;
type Error = ConnectError;
#[allow(clippy::type_complexity)]

View File

@ -70,8 +70,7 @@ impl<T> Clone for ConnectServiceFactory<T> {
}
}
impl<T: Address> ServiceFactory for ConnectServiceFactory<T> {
type Request = Connect<T>;
impl<T: Address> ServiceFactory<Connect<T>> for ConnectServiceFactory<T> {
type Response = Connection<T, TcpStream>;
type Error = ConnectError;
type Config = ();
@ -90,8 +89,7 @@ pub struct ConnectService<T> {
resolver: Resolver<T>,
}
impl<T: Address> Service for ConnectService<T> {
type Request = Connect<T>;
impl<T: Address> Service<Connect<T>> for ConnectService<T> {
type Response = Connection<T, TcpStream>;
type Error = ConnectError;
type Future = ConnectServiceResponse<T>;
@ -109,8 +107,8 @@ impl<T: Address> Service for ConnectService<T> {
}
enum ConnectState<T: Address> {
Resolve(<Resolver<T> as Service>::Future),
Connect(<TcpConnector<T> as Service>::Future),
Resolve(<Resolver<T> as Service<Connect<T>>>::Future),
Connect(<TcpConnector<T> as Service<Connect<T>>>::Future),
}
impl<T: Address> ConnectState<T> {
@ -160,8 +158,7 @@ pub struct TcpConnectService<T> {
resolver: Resolver<T>,
}
impl<T: Address + 'static> Service for TcpConnectService<T> {
type Request = Connect<T>;
impl<T: Address + 'static> Service<Connect<T>> for TcpConnectService<T> {
type Response = TcpStream;
type Error = ConnectError;
type Future = TcpConnectServiceResponse<T>;
@ -179,8 +176,8 @@ impl<T: Address + 'static> Service for TcpConnectService<T> {
}
enum TcpConnectState<T: Address> {
Resolve(<Resolver<T> as Service>::Future),
Connect(<TcpConnector<T> as Service>::Future),
Resolve(<Resolver<T> as Service<Connect<T>>>::Future),
Connect(<TcpConnector<T> as Service<Connect<T>>>::Future),
}
impl<T: Address> TcpConnectState<T> {