aboutsummaryrefslogtreecommitdiff
path: root/src/chain.rs
diff options
context:
space:
mode:
authorTill Höppner2016-02-23 17:00:53 +0100
committerTill Höppner2016-02-24 18:36:04 +0100
commitf01c278a26e0f248d188c10bdb852b0859b98b3b (patch)
tree3e729bf243011111a20b84f24aea3fbcb9f595f5 /src/chain.rs
parent815f31f5cef61709c50087c9f7601ea330929bb7 (diff)
downloadilc-f01c278a26e0f248d188c10bdb852b0859b98b3b.tar.gz
ilc-f01c278a26e0f248d188c10bdb852b0859b98b3b.tar.xz
ilc-f01c278a26e0f248d188c10bdb852b0859b98b3b.zip
Test CI
Diffstat (limited to 'src/chain.rs')
-rw-r--r--src/chain.rs36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/chain.rs b/src/chain.rs
index 9b9848a..a8014b8 100644
--- a/src/chain.rs
+++ b/src/chain.rs
@@ -1,19 +1,21 @@
-use std::io::{ Result, Read, Write };
+use std::io::{Read, Result, Write};
pub struct Chain<T> {
elem: Vec<T>,
- index: usize
+ index: usize,
}
impl<T: Read> Read for Chain<T> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
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)
+ Some(ref mut r) => {
+ match try!(r.read(buf)) {
+ 0 => self.index += 1,
+ n => return Ok(n),
+ }
+ }
+ None => return Ok(0),
}
}
}
@@ -23,11 +25,13 @@ impl<T: Write> Write for Chain<T> {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
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)
+ Some(ref mut r) => {
+ match try!(r.write(buf)) {
+ 0 => self.index += 1,
+ n => return Ok(n),
+ }
+ }
+ None => return Ok(0),
}
}
}
@@ -35,14 +39,16 @@ impl<T: Write> Write for Chain<T> {
fn flush(&mut self) -> Result<()> {
match self.elem.get_mut(self.index) {
Some(ref mut r) => r.flush(),
- None => Ok(())
+ None => Ok(()),
}
}
-
}
impl<T> Chain<T> {
pub fn new(elem: Vec<T>) -> Chain<T> {
- Chain { index: 0, elem: elem }
+ Chain {
+ index: 0,
+ elem: elem,
+ }
}
}