Last active
August 30, 2015 15:22
-
-
Save panicbit/d7132cd3de9bc97d6e55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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