From 51c55d30b3352270e4d1cbfd1482035f56f0a2c7 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Tue, 24 Feb 2015 18:50:33 +0100 Subject: [PATCH] Remove RefCell from IoConverter Seek is removed, so dynamic borrow checking is no longer needed --- src/ioconverter.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ioconverter.rs b/src/ioconverter.rs index d3eb2b5d..4a0e258d 100644 --- a/src/ioconverter.rs +++ b/src/ioconverter.rs @@ -1,24 +1,23 @@ use std::io; use std::io::prelude::*; use std::old_io; -use std::cell::RefCell; pub struct IoConverter { - inner: RefCell, + inner: T, } impl IoConverter { pub fn new(inner: T) -> IoConverter { - IoConverter { inner: RefCell::new(inner), } + IoConverter { inner: inner, } } pub fn into_inner(self) -> T { - self.inner.into_inner() + self.inner } } impl Writer for IoConverter { fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> { - match self.inner.borrow_mut().write_all(buf) { + match self.inner.write_all(buf) { Ok(()) => Ok(()), Err(..) => Err(old_io::standard_error(old_io::OtherIoError)), } @@ -27,13 +26,13 @@ impl Writer for IoConverter { impl Write for IoConverter { fn write(&mut self, buf: &[u8]) -> io::Result { - match self.inner.borrow_mut().write_all(buf) { + match self.inner.write_all(buf) { Ok(()) => Ok(buf.len()), Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some writing error", None)), } } fn flush(&mut self) -> io::Result<()> { - match self.inner.borrow_mut().flush() { + match self.inner.flush() { Ok(()) => Ok(()), Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some flushing error", None)), } @@ -42,7 +41,7 @@ impl Write for IoConverter { impl Read for IoConverter { fn read(&mut self, buf: &mut [u8]) -> io::Result { - match self.inner.borrow_mut().read(buf) { + match self.inner.read(buf) { Ok(v) => Ok(v), Err(ref e) if e.kind == old_io::EndOfFile => Ok(0), Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some reading error", None)), @@ -52,7 +51,7 @@ impl Read for IoConverter { impl Reader for IoConverter { fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { - match self.inner.borrow_mut().read(buf) { + match self.inner.read(buf) { Ok(0) if buf.len() > 0 => Err(old_io::standard_error(old_io::EndOfFile)), Ok(v) => Ok(v), Err(..) => Err(old_io::standard_error(old_io::OtherIoError)),