Remove io::read_error

The general idea is to remove conditions completely from I/O, so in the meantime
remove the read_error condition to mean the same thing as the io_error condition.
This commit is contained in:
Alex Crichton 2013-10-18 11:52:23 -07:00
parent e117aa0e2a
commit 6b70ddfba1
9 changed files with 42 additions and 52 deletions

View File

@ -18,7 +18,7 @@ use int;
use iter::Iterator;
use vec;
use rt::io::{Reader, Writer, Decorator};
use rt::io::{read_error, standard_error, EndOfFile, DEFAULT_BUF_SIZE};
use rt::io::{io_error, standard_error, EndOfFile, DEFAULT_BUF_SIZE};
use option::{Option, Some, None};
use unstable::finally::Finally;
use cast;
@ -41,8 +41,8 @@ pub trait ReaderUtil {
///
/// # Failure
///
/// Raises the same conditions as `read`. Additionally raises `read_error`
/// on EOF. If `read_error` is handled then `push_bytes` may push less
/// Raises the same conditions as `read`. Additionally raises `io_error`
/// on EOF. If `io_error` is handled then `push_bytes` may push less
/// than the requested number of bytes.
fn push_bytes(&mut self, buf: &mut ~[u8], len: uint);
@ -50,8 +50,8 @@ pub trait ReaderUtil {
///
/// # Failure
///
/// Raises the same conditions as `read`. Additionally raises `read_error`
/// on EOF. If `read_error` is handled then the returned vector may
/// Raises the same conditions as `read`. Additionally raises `io_error`
/// on EOF. If `io_error` is handled then the returned vector may
/// contain less than the requested number of bytes.
fn read_bytes(&mut self, len: uint) -> ~[u8];
@ -314,7 +314,7 @@ impl<T: Reader> ReaderUtil for T {
total_read += nread;
}
None => {
read_error::cond.raise(standard_error(EndOfFile));
io_error::cond.raise(standard_error(EndOfFile));
break;
}
}
@ -334,11 +334,11 @@ impl<T: Reader> ReaderUtil for T {
fn read_to_end(&mut self) -> ~[u8] {
let mut buf = vec::with_capacity(DEFAULT_BUF_SIZE);
let mut keep_reading = true;
do read_error::cond.trap(|e| {
do io_error::cond.trap(|e| {
if e.kind == EndOfFile {
keep_reading = false;
} else {
read_error::cond.raise(e)
io_error::cond.raise(e)
}
}).inside {
while keep_reading {
@ -641,7 +641,7 @@ mod test {
use cell::Cell;
use rt::io::mem::{MemReader, MemWriter};
use rt::io::mock::MockReader;
use rt::io::{read_error, placeholder_error};
use rt::io::{io_error, placeholder_error};
#[test]
fn read_byte() {
@ -681,10 +681,10 @@ mod test {
fn read_byte_error() {
let mut reader = MockReader::new();
reader.read = |_| {
read_error::cond.raise(placeholder_error());
io_error::cond.raise(placeholder_error());
None
};
do read_error::cond.trap(|_| {
do io_error::cond.trap(|_| {
}).inside {
let byte = reader.read_byte();
assert!(byte == None);
@ -722,11 +722,11 @@ mod test {
fn bytes_error() {
let mut reader = MockReader::new();
reader.read = |_| {
read_error::cond.raise(placeholder_error());
io_error::cond.raise(placeholder_error());
None
};
let mut it = reader.bytes();
do read_error::cond.trap(|_| ()).inside {
do io_error::cond.trap(|_| ()).inside {
let byte = it.next();
assert!(byte == None);
}
@ -765,7 +765,7 @@ mod test {
#[test]
fn read_bytes_eof() {
let mut reader = MemReader::new(~[10, 11]);
do read_error::cond.trap(|_| {
do io_error::cond.trap(|_| {
}).inside {
assert!(reader.read_bytes(4) == ~[10, 11]);
}
@ -806,7 +806,7 @@ mod test {
fn push_bytes_eof() {
let mut reader = MemReader::new(~[10, 11]);
let mut buf = ~[8, 9];
do read_error::cond.trap(|_| {
do io_error::cond.trap(|_| {
}).inside {
reader.push_bytes(&mut buf, 4);
assert!(buf == ~[8, 9, 10, 11]);
@ -824,13 +824,13 @@ mod test {
buf[0] = 10;
Some(1)
} else {
read_error::cond.raise(placeholder_error());
io_error::cond.raise(placeholder_error());
None
}
}
};
let mut buf = ~[8, 9];
do read_error::cond.trap(|_| { } ).inside {
do io_error::cond.trap(|_| { } ).inside {
reader.push_bytes(&mut buf, 4);
}
assert!(buf == ~[8, 9, 10]);
@ -850,7 +850,7 @@ mod test {
buf[0] = 10;
Some(1)
} else {
read_error::cond.raise(placeholder_error());
io_error::cond.raise(placeholder_error());
None
}
}
@ -903,7 +903,7 @@ mod test {
buf[1] = 11;
Some(2)
} else {
read_error::cond.raise(placeholder_error());
io_error::cond.raise(placeholder_error());
None
}
}

View File

@ -19,7 +19,7 @@ on a `ToCStr` object. This trait is already defined for common
objects such as strings and `Path` instances.
All operations in this module, including those as part of `FileStream` et al
block the task during execution. Most will raise `std::rt::io::{io_error,read_error}`
block the task during execution. Most will raise `std::rt::io::{io_error,io_error}`
conditions in the event of failure.
Also included in this module are the `FileInfo` and `DirectoryInfo` traits. When
@ -35,7 +35,7 @@ use c_str::ToCStr;
use super::{Reader, Writer, Seek};
use super::{SeekStyle, Read, Write};
use rt::rtio::{RtioFileStream, IoFactory, with_local_io};
use rt::io::{io_error, read_error, EndOfFile,
use rt::io::{io_error, EndOfFile,
FileMode, FileAccess, FileStat, IoError,
PathAlreadyExists, PathDoesntExist,
MismatchedFileTypeForOperation, ignore_io_error};
@ -361,7 +361,7 @@ impl Reader for FileStream {
Err(ioerr) => {
// EOF is indicated by returning None
if ioerr.kind != EndOfFile {
read_error::cond.raise(ioerr);
io_error::cond.raise(ioerr);
}
return None;
}
@ -388,7 +388,7 @@ impl Writer for FileStream {
match self.fd.flush() {
Ok(_) => (),
Err(ioerr) => {
read_error::cond.raise(ioerr);
io_error::cond.raise(ioerr);
}
}
}
@ -401,7 +401,7 @@ impl Seek for FileStream {
match res {
Ok(cursor) => cursor,
Err(ioerr) => {
read_error::cond.raise(ioerr);
io_error::cond.raise(ioerr);
return -1;
}
}
@ -415,7 +415,7 @@ impl Seek for FileStream {
()
},
Err(ioerr) => {
read_error::cond.raise(ioerr);
io_error::cond.raise(ioerr);
}
}
}

View File

@ -404,12 +404,6 @@ condition! {
pub io_error: IoError -> ();
}
// XXX: Can't put doc comments on macros
// Raised by `read` on error
condition! {
pub read_error: IoError -> ();
}
/// Helper for wrapper calls where you want to
/// ignore any io_errors that might be raised
pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
@ -429,7 +423,7 @@ pub trait Reader {
///
/// # Failure
///
/// Raises the `read_error` condition on error. If the condition
/// Raises the `io_error` condition on error. If the condition
/// is handled then no guarantee is made about the number of bytes
/// read and the contents of `buf`. If the condition is handled
/// returns `None` (XXX see below).

View File

@ -12,7 +12,7 @@ use option::{Option, Some, None};
use result::{Ok, Err};
use rt::io::net::ip::SocketAddr;
use rt::io::{Reader, Writer, Listener, Acceptor};
use rt::io::{io_error, read_error, EndOfFile};
use rt::io::{io_error, EndOfFile};
use rt::rtio::{IoFactory, with_local_io,
RtioSocket, RtioTcpListener, RtioTcpAcceptor, RtioTcpStream};
@ -67,7 +67,7 @@ impl Reader for TcpStream {
Err(ioerr) => {
// EOF is indicated by returning None
if ioerr.kind != EndOfFile {
read_error::cond.raise(ioerr);
io_error::cond.raise(ioerr);
}
return None;
}
@ -308,7 +308,7 @@ mod test {
let mut buf = [0];
let nread = stream.read(buf);
assert!(nread.is_none());
do read_error::cond.trap(|e| {
do io_error::cond.trap(|e| {
if cfg!(windows) {
assert_eq!(e.kind, NotConnected);
} else {
@ -343,7 +343,7 @@ mod test {
let mut buf = [0];
let nread = stream.read(buf);
assert!(nread.is_none());
do read_error::cond.trap(|e| {
do io_error::cond.trap(|e| {
if cfg!(windows) {
assert_eq!(e.kind, NotConnected);
} else {

View File

@ -12,7 +12,7 @@ use option::{Option, Some, None};
use result::{Ok, Err};
use rt::io::net::ip::SocketAddr;
use rt::io::{Reader, Writer};
use rt::io::{io_error, read_error, EndOfFile};
use rt::io::{io_error, EndOfFile};
use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, with_local_io};
pub struct UdpSocket {
@ -38,7 +38,7 @@ impl UdpSocket {
Err(ioerr) => {
// EOF is indicated by returning None
if ioerr.kind != EndOfFile {
read_error::cond.raise(ioerr);
io_error::cond.raise(ioerr);
}
None
}

View File

@ -16,7 +16,7 @@
use option::*;
use super::{Reader, Writer, Listener, Acceptor, Seek, SeekStyle};
use super::{standard_error, PreviousIoError, io_error, read_error, IoError};
use super::{standard_error, PreviousIoError, io_error, IoError};
fn prev_io_error() -> IoError {
standard_error(PreviousIoError)
@ -43,7 +43,7 @@ impl<R: Reader> Reader for Option<R> {
match *self {
Some(ref mut reader) => reader.read(buf),
None => {
read_error::cond.raise(prev_io_error());
io_error::cond.raise(prev_io_error());
None
}
}
@ -107,7 +107,7 @@ mod test {
use option::*;
use super::super::mem::*;
use rt::test::*;
use super::super::{PreviousIoError, io_error, read_error};
use super::super::{PreviousIoError, io_error, io_error};
#[test]
fn test_option_writer() {
@ -161,7 +161,7 @@ mod test {
let mut buf = [];
let mut called = false;
do read_error::cond.trap(|err| {
do io_error::cond.trap(|err| {
assert_eq!(err.kind, PreviousIoError);
called = true;
}).inside {

View File

@ -15,7 +15,7 @@
use prelude::*;
use super::{Reader, Writer};
use rt::io::{io_error, read_error, EndOfFile};
use rt::io::{io_error, EndOfFile};
use rt::rtio::RtioPipe;
pub struct PipeStream {
@ -35,7 +35,7 @@ impl Reader for PipeStream {
Err(ioerr) => {
// EOF is indicated by returning None
if ioerr.kind != EndOfFile {
read_error::cond.raise(ioerr);
io_error::cond.raise(ioerr);
}
return None;
}

View File

@ -93,7 +93,7 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
let file = res_rel_file(cx, sp, &Path::new(file));
let mut error = None;
let bytes = do io::read_error::cond.trap(|e| error = Some(e)).inside {
let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside {
file.open_reader(io::Open).read_to_end()
};
match error {
@ -120,10 +120,8 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
let file = res_rel_file(cx, sp, &Path::new(file));
let mut error = None;
let bytes = do io::read_error::cond.trap(|e| error = Some(e)).inside {
do io::io_error::cond.trap(|e| error = Some(e)).inside {
file.open_reader(io::Open).read_to_end()
}
let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside {
file.open_reader(io::Open).read_to_end()
};
match error {
Some(e) => {

View File

@ -271,9 +271,7 @@ pub fn file_to_filemap(sess: @mut ParseSess, path: &Path, spanopt: Option<Span>)
};
let mut error = None;
let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside {
do io::read_error::cond.trap(|e| error = Some(e)).inside {
path.open_reader(io::Open).read_to_end()
}
path.open_reader(io::Open).read_to_end()
};
match error {
Some(e) => {