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:21:24 +0100
commite866dceae987acd51d43bd457351bd2188c5f95a (patch)
tree2cc5a67492bdf00ff68041656a1e870b2b4de17f /src/chain.rs
parent815f31f5cef61709c50087c9f7601ea330929bb7 (diff)
downloadilc-e866dceae987acd51d43bd457351bd2188c5f95a.tar.gz
ilc-e866dceae987acd51d43bd457351bd2188c5f95a.tar.xz
ilc-e866dceae987acd51d43bd457351bd2188c5f95a.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,
+ }
}
}