1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 17:52:40 +01:00
actix-extras/src/ws/transport.rs

50 lines
1.2 KiB
Rust
Raw Normal View History

2018-12-11 03:08:33 +01:00
use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_service::{IntoService, Service};
use actix_utils::framed::{FramedTransport, FramedTransportError};
2018-10-05 23:30:40 +02:00
use futures::{Future, Poll};
2018-10-10 22:20:00 +02:00
use super::{Codec, Frame, Message};
2018-10-05 23:30:40 +02:00
pub struct Transport<S, T>
where
2019-02-02 05:18:44 +01:00
S: Service<Request = Frame, Response = Message> + 'static,
2018-10-05 23:30:40 +02:00
T: AsyncRead + AsyncWrite,
{
inner: FramedTransport<S, T, Codec>,
}
impl<S, T> Transport<S, T>
where
T: AsyncRead + AsyncWrite,
2019-02-02 05:18:44 +01:00
S: Service<Request = Frame, Response = Message>,
2018-10-05 23:30:40 +02:00
S::Future: 'static,
S::Error: 'static,
{
2019-02-02 05:18:44 +01:00
pub fn new<F: IntoService<S>>(io: T, service: F) -> Self {
2018-10-05 23:30:40 +02:00
Transport {
inner: FramedTransport::new(Framed::new(io, Codec::new()), service),
}
}
2019-02-02 05:18:44 +01:00
pub fn with<F: IntoService<S>>(framed: Framed<T, Codec>, service: F) -> Self {
2018-10-05 23:30:40 +02:00
Transport {
inner: FramedTransport::new(framed, service),
}
}
}
impl<S, T> Future for Transport<S, T>
where
T: AsyncRead + AsyncWrite,
2019-02-02 05:18:44 +01:00
S: Service<Request = Frame, Response = Message>,
2018-10-05 23:30:40 +02:00
S::Future: 'static,
S::Error: 'static,
{
type Item = ();
type Error = FramedTransportError<S::Error, Codec>;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
self.inner.poll()
}
}