#[macro_use] extern crate serde_derive; use futures_util::future::poll_fn; use std::task::{Context, Poll}; use tower_service::Service; async fn ready, Request>(svc: &mut S) -> Result<(), S::Error> { poll_fn(|cx| svc.poll_ready(cx)).await } #[derive(Serialize, Deserialize)] pub struct Request { tag: usize, value: u32, } impl Request { pub fn new(val: u32) -> Self { Request { tag: 0, value: val } } pub fn check(&self, expected: u32) { assert_eq!(self.value, expected); } } #[derive(Serialize, Deserialize)] pub struct Response { tag: usize, value: u32, } impl From for Response { fn from(r: Request) -> Response { Response { tag: r.tag, value: r.value, } } } impl Response { pub fn check(&self, expected: u32) { assert_eq!(self.value, expected); } pub fn get_tag(&self) -> usize { self.tag } } impl Request { pub fn set_tag(&mut self, tag: usize) { self.tag = tag; } } struct PanicError; use std::fmt; impl From for PanicError where E: fmt::Debug, { fn from(e: E) -> Self { panic!("{:?}", e) } } fn unwrap(r: Result) -> T { if let Ok(t) = r { t } else { unreachable!(); } } struct EchoService; impl Service for EchoService { type Response = Response; type Error = (); type Future = futures_util::future::Ready>; fn poll_ready(&mut self, _: &mut Context) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, r: Request) -> Self::Future { futures_util::future::ok(Response::from(r)) } } mod multiplex; mod pipeline;