mirror of
https://github.com/actix/actix-extras.git
synced 2025-07-01 12:15:08 +02:00
use new Service and NewService traits
This commit is contained in:
@ -26,7 +26,7 @@ pub type DefaultClient = Client<DefaultConnector>;
|
||||
/// WebSocket's client
|
||||
pub struct Client<T>
|
||||
where
|
||||
T: Service<Error = ConnectorError>,
|
||||
T: Service<TcpConnect, Error = ConnectorError>,
|
||||
T::Response: AsyncRead + AsyncWrite,
|
||||
{
|
||||
connector: T,
|
||||
@ -34,7 +34,7 @@ where
|
||||
|
||||
impl<T> Client<T>
|
||||
where
|
||||
T: Service<Request = TcpConnect, Error = ConnectorError>,
|
||||
T: Service<TcpConnect, Error = ConnectorError>,
|
||||
T::Response: AsyncRead + AsyncWrite,
|
||||
{
|
||||
/// Create new websocket's client factory
|
||||
@ -51,7 +51,7 @@ impl Default for Client<DefaultConnector> {
|
||||
|
||||
impl<T> Clone for Client<T>
|
||||
where
|
||||
T: Service<Request = TcpConnect, Error = ConnectorError> + Clone,
|
||||
T: Service<TcpConnect, Error = ConnectorError> + Clone,
|
||||
T::Response: AsyncRead + AsyncWrite,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
@ -61,13 +61,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Service for Client<T>
|
||||
impl<T> Service<Connect> for Client<T>
|
||||
where
|
||||
T: Service<Request = TcpConnect, Error = ConnectorError>,
|
||||
T: Service<TcpConnect, Error = ConnectorError>,
|
||||
T::Response: AsyncRead + AsyncWrite + 'static,
|
||||
T::Future: 'static,
|
||||
{
|
||||
type Request = Connect;
|
||||
type Response = Framed<T::Response, Codec>;
|
||||
type Error = ClientError;
|
||||
type Future = Either<
|
||||
@ -79,7 +78,7 @@ where
|
||||
self.connector.poll_ready().map_err(ClientError::from)
|
||||
}
|
||||
|
||||
fn call(&mut self, mut req: Self::Request) -> Self::Future {
|
||||
fn call(&mut self, mut req: Connect) -> Self::Future {
|
||||
if let Some(e) = req.err.take() {
|
||||
Either::A(err(e))
|
||||
} else if let Some(e) = req.http_err.take() {
|
||||
|
@ -20,8 +20,7 @@ impl<T> Default for VerifyWebSockets<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> NewService for VerifyWebSockets<T> {
|
||||
type Request = (Request, Framed<T, Codec>);
|
||||
impl<T> NewService<(Request, Framed<T, Codec>)> for VerifyWebSockets<T> {
|
||||
type Response = (Request, Framed<T, Codec>);
|
||||
type Error = (HandshakeError, Framed<T, Codec>);
|
||||
type InitError = ();
|
||||
@ -33,8 +32,7 @@ impl<T> NewService for VerifyWebSockets<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Service for VerifyWebSockets<T> {
|
||||
type Request = (Request, Framed<T, Codec>);
|
||||
impl<T> Service<(Request, Framed<T, Codec>)> for VerifyWebSockets<T> {
|
||||
type Response = (Request, Framed<T, Codec>);
|
||||
type Error = (HandshakeError, Framed<T, Codec>);
|
||||
type Future = FutureResult<Self::Response, Self::Error>;
|
||||
@ -43,7 +41,7 @@ impl<T> Service for VerifyWebSockets<T> {
|
||||
Ok(Async::Ready(()))
|
||||
}
|
||||
|
||||
fn call(&mut self, (req, framed): Self::Request) -> Self::Future {
|
||||
fn call(&mut self, (req, framed): (Request, Framed<T, Codec>)) -> Self::Future {
|
||||
match verify_handshake(&req) {
|
||||
Err(e) => Err((e, framed)).into_future(),
|
||||
Ok(_) => Ok((req, framed)).into_future(),
|
||||
|
@ -8,7 +8,7 @@ use super::{Codec, Frame, Message};
|
||||
|
||||
pub struct Transport<S, T>
|
||||
where
|
||||
S: Service,
|
||||
S: Service<Frame, Response = Message>,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
{
|
||||
inner: FramedTransport<S, T, Codec>,
|
||||
@ -17,17 +17,17 @@ where
|
||||
impl<S, T> Transport<S, T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request = Frame, Response = Message>,
|
||||
S: Service<Frame, Response = Message>,
|
||||
S::Future: 'static,
|
||||
S::Error: 'static,
|
||||
{
|
||||
pub fn new<F: IntoService<S>>(io: T, service: F) -> Self {
|
||||
pub fn new<F: IntoService<S, Frame>>(io: T, service: F) -> Self {
|
||||
Transport {
|
||||
inner: FramedTransport::new(Framed::new(io, Codec::new()), service),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with<F: IntoService<S>>(framed: Framed<T, Codec>, service: F) -> Self {
|
||||
pub fn with<F: IntoService<S, Frame>>(framed: Framed<T, Codec>, service: F) -> Self {
|
||||
Transport {
|
||||
inner: FramedTransport::new(framed, service),
|
||||
}
|
||||
@ -37,7 +37,7 @@ where
|
||||
impl<S, T> Future for Transport<S, T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request = Frame, Response = Message>,
|
||||
S: Service<Frame, Response = Message>,
|
||||
S::Future: 'static,
|
||||
S::Error: 'static,
|
||||
{
|
||||
|
Reference in New Issue
Block a user