Skip to content

Instantly share code, notes, and snippets.

@panicbit
Last active August 30, 2015 15:22
Show Gist options
  • Save panicbit/d7132cd3de9bc97d6e55 to your computer and use it in GitHub Desktop.
Save panicbit/d7132cd3de9bc97d6e55 to your computer and use it in GitHub Desktop.
use std::io::{self,Read};
use std::borrow::Borrow;
use iron::response::{WriteBody,ResponseBody};
pub struct BodyChain<T, U>(pub T, pub U);
impl <T: WriteBody, U: WriteBody> WriteBody for BodyChain<T, U> {
fn write_body(&mut self, res: &mut ResponseBody) -> io::Result<()> {
let &mut BodyChain(ref mut a, ref mut b) = self;
a.write_body(res).and_then(|_| b.write_body(res))
}
}
pub fn chain_body<T,U,TO,UO>(a: U, b: T) -> Box<WriteBody + Send> where
T: ToOwned<Owned=TO>,
U: ToOwned<Owned=UO>,
TO: WriteBody + Borrow<T> + Send + 'static,
UO: WriteBody + Borrow<U> + Send + 'static
{
Box::new(BodyChain(a.to_owned(), b.to_owned()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment