aboutsummaryrefslogtreecommitdiff
path: root/src/chain.rs
diff options
context:
space:
mode:
authorTill Hoeppner2015-07-26 23:56:52 +0200
committerTill Hoeppner2015-07-26 23:56:52 +0200
commit4914e6a56547dcbe0fdbcfd7eae62a3d416875a5 (patch)
tree3cf2fd6e9b0b0376a23a0ddb32c4242d6a6fec9b /src/chain.rs
parent6a817022a7301d89a2d93be400294f78b5dae0b4 (diff)
downloadilc-4914e6a56547dcbe0fdbcfd7eae62a3d416875a5.tar.gz
ilc-4914e6a56547dcbe0fdbcfd7eae62a3d416875a5.tar.xz
ilc-4914e6a56547dcbe0fdbcfd7eae62a3d416875a5.zip
Add glob-ing for input files
Diffstat (limited to 'src/chain.rs')
-rw-r--r--src/chain.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/chain.rs b/src/chain.rs
new file mode 100644
index 0000000..9b9848a
--- /dev/null
+++ b/src/chain.rs
@@ -0,0 +1,48 @@
+use std::io::{ Result, Read, Write };
+
+pub struct Chain<T> {
+ elem: Vec<T>,
+ 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)
+ }
+ }
+ }
+}
+
+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)
+ }
+ }
+ }
+
+ fn flush(&mut self) -> Result<()> {
+ match self.elem.get_mut(self.index) {
+ Some(ref mut r) => r.flush(),
+ None => Ok(())
+ }
+ }
+
+}
+
+impl<T> Chain<T> {
+ pub fn new(elem: Vec<T>) -> Chain<T> {
+ Chain { index: 0, elem: elem }
+ }
+}