tokio_proto/simple/pipeline/
mod.rsmod client;
pub use self::client::ClientProto;
pub use self::client::ClientService;
mod server;
pub use self::server::ServerProto;
#[derive(Debug)]
pub struct Pipeline;
mod lift {
use std::io;
use std::marker::PhantomData;
use streaming::pipeline::{Frame, Transport};
use futures::{Future, Stream, Sink, StartSend, Poll, Async, AsyncSink};
pub struct LiftTransport<T, E>(pub T, pub PhantomData<E>);
pub struct LiftBind<A, F, E> {
fut: F,
marker: PhantomData<(A, E)>,
}
impl<E, T: Stream<Error = io::Error>> Stream for LiftTransport<T, E> {
type Item = Frame<T::Item, (), E>;
type Error = io::Error;
fn poll(&mut self) -> Poll<Option<Self::Item>, io::Error> {
let item = try_ready!(self.0.poll());
Ok(item.map(|msg| {
Frame::Message { message: msg, body: false }
}).into())
}
}
impl<E, T: Sink<SinkError = io::Error>> Sink for LiftTransport<T, E> {
type SinkItem = Frame<T::SinkItem, (), E>;
type SinkError = io::Error;
fn start_send(&mut self, request: Self::SinkItem)
-> StartSend<Self::SinkItem, io::Error> {
if let Frame::Message { message, body } = request {
if !body {
match try!(self.0.start_send(message)) {
AsyncSink::Ready => return Ok(AsyncSink::Ready),
AsyncSink::NotReady(msg) => {
let msg = Frame::Message { message: msg, body: false };
return Ok(AsyncSink::NotReady(msg))
}
}
}
}
Err(io::Error::new(io::ErrorKind::Other, "no support for streaming"))
}
fn poll_complete(&mut self) -> Poll<(), io::Error> {
self.0.poll_complete()
}
fn close(&mut self) -> Poll<(), io::Error> {
self.0.close()
}
}
impl<T, E: 'static> Transport for LiftTransport<T, E>
where T: 'static + Stream<Error = io::Error> + Sink<SinkError = io::Error>
{}
impl<A, F, E> LiftBind<A, F, E> {
pub fn lift(f: F) -> LiftBind<A, F, E> {
LiftBind {
fut: f,
marker: PhantomData,
}
}
}
impl<A, F, E> Future for LiftBind<A, F, E> where F: Future<Error = io::Error> {
type Item = LiftTransport<F::Item, E>;
type Error = io::Error;
fn poll(&mut self) -> Poll<Self::Item, io::Error> {
Ok(Async::Ready(LiftTransport(try_ready!(self.fut.poll()), PhantomData)))
}
}
}