use std::io::{ Result, Read, Write }; pub struct Chain { elem: Vec, index: usize } impl Read for Chain { fn read(&mut self, buf: &mut [u8]) -> Result { loop { match self.elem.get_mut(self.index) { Some(ref mut r) => match try!(r.read(buf)) { 0 => self.index += 1, n => return Ok(n) }, None => return Ok(0) } } } } impl Write for Chain { fn write(&mut self, buf: &[u8]) -> Result { loop { match self.elem.get_mut(self.index) { Some(ref mut r) => match try!(r.write(buf)) { 0 => self.index += 1, n => return Ok(n) }, None => return Ok(0) } } } fn flush(&mut self) -> Result<()> { match self.elem.get_mut(self.index) { Some(ref mut r) => r.flush(), None => Ok(()) } } } impl Chain { pub fn new(elem: Vec) -> Chain { Chain { index: 0, elem: elem } } }