use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; use actix_codec::{AsyncRead, AsyncWrite, Framed}; use actix_service::{IntoService, Service}; use actix_utils::framed; use super::{Codec, Frame, Message}; pub struct Dispatcher where S: Service + 'static, T: AsyncRead + AsyncWrite, { inner: framed::Dispatcher, } impl Dispatcher where T: AsyncRead + AsyncWrite, S: Service, S::Future: 'static, S::Error: 'static, { pub fn new>(io: T, service: F) -> Self { Dispatcher { inner: framed::Dispatcher::new(Framed::new(io, Codec::new()), service), } } pub fn with>(framed: Framed, service: F) -> Self { Dispatcher { inner: framed::Dispatcher::new(framed, service), } } } impl Future for Dispatcher where T: AsyncRead + AsyncWrite, S: Service, S::Future: 'static, S::Error: 'static, { type Output = Result<(), framed::DispatcherError>; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { Pin::new(&mut self.inner).poll(cx) } }