Remove RefCell from IoConverter
Seek is removed, so dynamic borrow checking is no longer needed
This commit is contained in:
parent
518b40aabc
commit
51c55d30b3
1 changed files with 8 additions and 9 deletions
|
@ -1,24 +1,23 @@
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::old_io;
|
use std::old_io;
|
||||||
use std::cell::RefCell;
|
|
||||||
|
|
||||||
pub struct IoConverter<T> {
|
pub struct IoConverter<T> {
|
||||||
inner: RefCell<T>,
|
inner: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> IoConverter<T> {
|
impl<T> IoConverter<T> {
|
||||||
pub fn new(inner: T) -> IoConverter<T> {
|
pub fn new(inner: T) -> IoConverter<T> {
|
||||||
IoConverter { inner: RefCell::new(inner), }
|
IoConverter { inner: inner, }
|
||||||
}
|
}
|
||||||
pub fn into_inner(self) -> T {
|
pub fn into_inner(self) -> T {
|
||||||
self.inner.into_inner()
|
self.inner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: Write> Writer for IoConverter<W> {
|
impl<W: Write> Writer for IoConverter<W> {
|
||||||
fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> {
|
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(()),
|
Ok(()) => Ok(()),
|
||||||
Err(..) => Err(old_io::standard_error(old_io::OtherIoError)),
|
Err(..) => Err(old_io::standard_error(old_io::OtherIoError)),
|
||||||
}
|
}
|
||||||
|
@ -27,13 +26,13 @@ impl<W: Write> Writer for IoConverter<W> {
|
||||||
|
|
||||||
impl<W: Writer> Write for IoConverter<W> {
|
impl<W: Writer> Write for IoConverter<W> {
|
||||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||||
match self.inner.borrow_mut().write_all(buf) {
|
match self.inner.write_all(buf) {
|
||||||
Ok(()) => Ok(buf.len()),
|
Ok(()) => Ok(buf.len()),
|
||||||
Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some writing error", None)),
|
Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some writing error", None)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn flush(&mut self) -> io::Result<()> {
|
fn flush(&mut self) -> io::Result<()> {
|
||||||
match self.inner.borrow_mut().flush() {
|
match self.inner.flush() {
|
||||||
Ok(()) => Ok(()),
|
Ok(()) => Ok(()),
|
||||||
Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some flushing error", None)),
|
Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some flushing error", None)),
|
||||||
}
|
}
|
||||||
|
@ -42,7 +41,7 @@ impl<W: Writer> Write for IoConverter<W> {
|
||||||
|
|
||||||
impl<R: Reader> Read for IoConverter<R> {
|
impl<R: Reader> Read for IoConverter<R> {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
match self.inner.borrow_mut().read(buf) {
|
match self.inner.read(buf) {
|
||||||
Ok(v) => Ok(v),
|
Ok(v) => Ok(v),
|
||||||
Err(ref e) if e.kind == old_io::EndOfFile => Ok(0),
|
Err(ref e) if e.kind == old_io::EndOfFile => Ok(0),
|
||||||
Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some reading error", None)),
|
Err(..) => Err(io::Error::new(io::ErrorKind::Other, "Some reading error", None)),
|
||||||
|
@ -52,7 +51,7 @@ impl<R: Reader> Read for IoConverter<R> {
|
||||||
|
|
||||||
impl<R: Read> Reader for IoConverter<R> {
|
impl<R: Read> Reader for IoConverter<R> {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult<usize> {
|
||||||
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(0) if buf.len() > 0 => Err(old_io::standard_error(old_io::EndOfFile)),
|
||||||
Ok(v) => Ok(v),
|
Ok(v) => Ok(v),
|
||||||
Err(..) => Err(old_io::standard_error(old_io::OtherIoError)),
|
Err(..) => Err(old_io::standard_error(old_io::OtherIoError)),
|
||||||
|
|
Loading…
Add table
Reference in a new issue