diff options
| author | bors <bors@rust-lang.org> | 2015-01-07 05:31:23 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-07 05:31:23 +0000 |
| commit | 9e4e524e0eb17c8f463e731f23b544003e8709c6 (patch) | |
| tree | 916024d35e08f0826c20654f629ec596b5cb1f14 /src/libstd/io | |
| parent | ea6f65c5f1a3f84e010d2cef02a0160804e9567a (diff) | |
| parent | a64000820f0fc32be4d7535a9a92418a434fa4ba (diff) | |
| download | rust-9e4e524e0eb17c8f463e731f23b544003e8709c6.tar.gz rust-9e4e524e0eb17c8f463e731f23b544003e8709c6.zip | |
auto merge of #20677 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/buffered.rs | 57 | ||||
| -rw-r--r-- | src/libstd/io/comm_adapters.rs | 9 | ||||
| -rw-r--r-- | src/libstd/io/fs.rs | 66 | ||||
| -rw-r--r-- | src/libstd/io/mem.rs | 27 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 58 | ||||
| -rw-r--r-- | src/libstd/io/net/addrinfo.rs | 10 | ||||
| -rw-r--r-- | src/libstd/io/net/ip.rs | 12 | ||||
| -rw-r--r-- | src/libstd/io/net/pipe.rs | 12 | ||||
| -rw-r--r-- | src/libstd/io/net/tcp.rs | 32 | ||||
| -rw-r--r-- | src/libstd/io/process.rs | 25 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/timer.rs | 6 | ||||
| -rw-r--r-- | src/libstd/io/util.rs | 6 |
13 files changed, 173 insertions, 151 deletions
diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index d590aa84194..74c503e6f2b 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -15,7 +15,7 @@ use cmp; use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult}; use iter::{IteratorExt, ExactSizeIterator}; -use ops::Drop; +use ops::{Drop, Index}; use option::Option; use option::Option::{Some, None}; use result::Result::Ok; @@ -23,9 +23,6 @@ use slice::{SliceExt}; use slice; use vec::Vec; -// NOTE: for old macros; remove after the next snapshot -#[cfg(stage0)] use result::Result::Err; - /// Wraps a Reader and buffers input from it /// /// It can be excessively inefficient to work directly with a `Reader`. For @@ -100,7 +97,7 @@ impl<R: Reader> Buffer for BufferedReader<R> { self.cap = try!(self.inner.read(self.buf.as_mut_slice())); self.pos = 0; } - Ok(self.buf[self.pos..self.cap]) + Ok(self.buf.index(&(self.pos..self.cap))) } fn consume(&mut self, amt: uint) { @@ -117,7 +114,7 @@ impl<R: Reader> Reader for BufferedReader<R> { let nread = { let available = try!(self.fill_buf()); let nread = cmp::min(available.len(), buf.len()); - slice::bytes::copy_memory(buf, available[..nread]); + slice::bytes::copy_memory(buf, available.index(&(0..nread))); nread }; self.pos += nread; @@ -171,7 +168,7 @@ impl<W: Writer> BufferedWriter<W> { fn flush_buf(&mut self) -> IoResult<()> { if self.pos != 0 { - let ret = self.inner.as_mut().unwrap().write(self.buf[..self.pos]); + let ret = self.inner.as_mut().unwrap().write(self.buf.index(&(0..self.pos))); self.pos = 0; ret } else { @@ -263,9 +260,9 @@ impl<W: Writer> Writer for LineBufferedWriter<W> { fn write(&mut self, buf: &[u8]) -> IoResult<()> { match buf.iter().rposition(|&b| b == b'\n') { Some(i) => { - try!(self.inner.write(buf[..i + 1])); + try!(self.inner.write(buf.index(&(0..(i + 1))))); try!(self.inner.flush()); - try!(self.inner.write(buf[i + 1..])); + try!(self.inner.write(buf.index(&((i + 1)..)))); Ok(()) } None => self.inner.write(buf), @@ -472,41 +469,37 @@ mod test { writer.write(&[0, 1]).unwrap(); let b: &[_] = &[]; - assert_eq!(writer.get_ref()[], b); + assert_eq!(&writer.get_ref()[], b); writer.write(&[2]).unwrap(); let b: &[_] = &[0, 1]; - assert_eq!(writer.get_ref()[], b); + assert_eq!(&writer.get_ref()[], b); writer.write(&[3]).unwrap(); - assert_eq!(writer.get_ref()[], b); + assert_eq!(&writer.get_ref()[], b); writer.flush().unwrap(); let a: &[_] = &[0, 1, 2, 3]; - assert_eq!(a, writer.get_ref()[]); + assert_eq!(a, &writer.get_ref()[]); writer.write(&[4]).unwrap(); writer.write(&[5]).unwrap(); - assert_eq!(a, writer.get_ref()[]); + assert_eq!(a, &writer.get_ref()[]); writer.write(&[6]).unwrap(); let a: &[_] = &[0, 1, 2, 3, 4, 5]; - assert_eq!(a, - writer.get_ref()[]); + assert_eq!(a, &writer.get_ref()[]); writer.write(&[7, 8]).unwrap(); let a: &[_] = &[0, 1, 2, 3, 4, 5, 6]; - assert_eq!(a, - writer.get_ref()[]); + assert_eq!(a, &writer.get_ref()[]); writer.write(&[9, 10, 11]).unwrap(); let a: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; - assert_eq!(a, - writer.get_ref()[]); + assert_eq!(a, &writer.get_ref()[]); writer.flush().unwrap(); - assert_eq!(a, - writer.get_ref()[]); + assert_eq!(a, &writer.get_ref()[]); } #[test] @@ -514,10 +507,10 @@ mod test { let mut w = BufferedWriter::with_capacity(3, Vec::new()); w.write(&[0, 1]).unwrap(); let a: &[_] = &[]; - assert_eq!(a, w.get_ref()[]); + assert_eq!(a, &w.get_ref()[]); let w = w.into_inner(); let a: &[_] = &[0, 1]; - assert_eq!(a, w[]); + assert_eq!(a, w.index(&FullRange)); } // This is just here to make sure that we don't infinite loop in the @@ -559,21 +552,21 @@ mod test { let mut writer = LineBufferedWriter::new(Vec::new()); writer.write(&[0]).unwrap(); let b: &[_] = &[]; - assert_eq!(writer.get_ref()[], b); + assert_eq!(&writer.get_ref()[], b); writer.write(&[1]).unwrap(); - assert_eq!(writer.get_ref()[], b); + assert_eq!(&writer.get_ref()[], b); writer.flush().unwrap(); let b: &[_] = &[0, 1]; - assert_eq!(writer.get_ref()[], b); + assert_eq!(&writer.get_ref()[], b); writer.write(&[0, b'\n', 1, b'\n', 2]).unwrap(); let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n']; - assert_eq!(writer.get_ref()[], b); + assert_eq!(&writer.get_ref()[], b); writer.flush().unwrap(); let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2]; - assert_eq!(writer.get_ref()[], b); + assert_eq!(&writer.get_ref()[], b); writer.write(&[3, b'\n']).unwrap(); let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2, 3, b'\n']; - assert_eq!(writer.get_ref()[], b); + assert_eq!(&writer.get_ref()[], b); } #[test] @@ -614,14 +607,14 @@ mod test { #[test] fn read_char_buffered() { let buf = [195u8, 159u8]; - let mut reader = BufferedReader::with_capacity(1, buf[]); + let mut reader = BufferedReader::with_capacity(1, buf.index(&FullRange)); assert_eq!(reader.read_char(), Ok('ß')); } #[test] fn test_chars() { let buf = [195u8, 159u8, b'a']; - let mut reader = BufferedReader::with_capacity(1, buf[]); + let mut reader = BufferedReader::with_capacity(1, buf.index(&FullRange)); let mut it = reader.chars(); assert_eq!(it.next(), Some(Ok('ß'))); assert_eq!(it.next(), Some(Ok('a'))); diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index f47f6237b72..bce097e17ef 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -13,6 +13,7 @@ use cmp; use sync::mpsc::{Sender, Receiver}; use io; use option::Option::{None, Some}; +use ops::Index; use result::Result::{Ok, Err}; use slice::{bytes, SliceExt}; use super::{Buffer, Reader, Writer, IoResult}; @@ -90,7 +91,7 @@ impl Reader for ChanReader { Some(src) => { let dst = buf.slice_from_mut(num_read); let count = cmp::min(src.len(), dst.len()); - bytes::copy_memory(dst, src[..count]); + bytes::copy_memory(dst, src.index(&(0..count))); count }, None => 0, @@ -172,7 +173,7 @@ mod test { tx.send(vec![3u8, 4u8]).unwrap(); tx.send(vec![5u8, 6u8]).unwrap(); tx.send(vec![7u8, 8u8]).unwrap(); - }).detach(); + }); let mut reader = ChanReader::new(rx); let mut buf = [0u8; 3]; @@ -215,7 +216,7 @@ mod test { tx.send(b"rld\nhow ".to_vec()).unwrap(); tx.send(b"are you?".to_vec()).unwrap(); tx.send(b"".to_vec()).unwrap(); - }).detach(); + }); let mut reader = ChanReader::new(rx); @@ -234,7 +235,7 @@ mod test { writer.write_be_u32(42).unwrap(); let wanted = vec![0u8, 0u8, 0u8, 42u8]; - let got = match Thread::spawn(move|| { rx.recv().unwrap() }).join() { + let got = match Thread::scoped(move|| { rx.recv().unwrap() }).join() { Ok(got) => got, Err(_) => panic!(), }; diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 4691c06c1de..eadca8e42e5 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -156,7 +156,7 @@ impl File { }) } }).update_err("couldn't open path as file", |e| { - format!("{}; path={}; mode={}; access={}", e, path.display(), + format!("{}; path={:?}; mode={}; access={}", e, path.display(), mode_string(mode), access_string(access)) }) } @@ -211,7 +211,7 @@ impl File { pub fn fsync(&mut self) -> IoResult<()> { self.fd.fsync() .update_err("couldn't fsync file", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{}; path={:?}", e, self.path.display())) } /// This function is similar to `fsync`, except that it may not synchronize @@ -221,7 +221,7 @@ impl File { pub fn datasync(&mut self) -> IoResult<()> { self.fd.datasync() .update_err("couldn't datasync file", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{}; path={:?}", e, self.path.display())) } /// Either truncates or extends the underlying file, updating the size of @@ -235,7 +235,7 @@ impl File { pub fn truncate(&mut self, size: i64) -> IoResult<()> { self.fd.truncate(size) .update_err("couldn't truncate file", |e| - format!("{}; path={}; size={}", e, self.path.display(), size)) + format!("{}; path={:?}; size={:?}", e, self.path.display(), size)) } /// Returns true if the stream has reached the end of the file. @@ -255,7 +255,7 @@ impl File { pub fn stat(&self) -> IoResult<FileStat> { self.fd.fstat() .update_err("couldn't fstat file", |e| - format!("{}; path={}", e, self.path.display())) + format!("{}; path={:?}", e, self.path.display())) } } @@ -283,7 +283,7 @@ impl File { pub fn unlink(path: &Path) -> IoResult<()> { fs_imp::unlink(path) .update_err("couldn't unlink path", |e| - format!("{}; path={}", e, path.display())) + format!("{}; path={:?}", e, path.display())) } /// Given a path, query the file system to get information about a file, @@ -310,7 +310,7 @@ pub fn unlink(path: &Path) -> IoResult<()> { pub fn stat(path: &Path) -> IoResult<FileStat> { fs_imp::stat(path) .update_err("couldn't stat path", |e| - format!("{}; path={}", e, path.display())) + format!("{}; path={:?}", e, path.display())) } /// Perform the same operation as the `stat` function, except that this @@ -324,7 +324,7 @@ pub fn stat(path: &Path) -> IoResult<FileStat> { pub fn lstat(path: &Path) -> IoResult<FileStat> { fs_imp::lstat(path) .update_err("couldn't lstat path", |e| - format!("{}; path={}", e, path.display())) + format!("{}; path={:?}", e, path.display())) } /// Rename a file or directory to a new name. @@ -346,7 +346,7 @@ pub fn lstat(path: &Path) -> IoResult<FileStat> { pub fn rename(from: &Path, to: &Path) -> IoResult<()> { fs_imp::rename(from, to) .update_err("couldn't rename path", |e| - format!("{}; from={}; to={}", e, from.display(), to.display())) + format!("{}; from={:?}; to={:?}", e, from.display(), to.display())) } /// Copies the contents of one file to another. This function will also @@ -380,7 +380,7 @@ pub fn rename(from: &Path, to: &Path) -> IoResult<()> { pub fn copy(from: &Path, to: &Path) -> IoResult<()> { fn update_err<T>(result: IoResult<T>, from: &Path, to: &Path) -> IoResult<T> { result.update_err("couldn't copy path", |e| { - format!("{}; from={}; to={}", e, from.display(), to.display()) + format!("{}; from={:?}; to={:?}", e, from.display(), to.display()) }) } @@ -424,14 +424,14 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> { pub fn chmod(path: &Path, mode: io::FilePermission) -> IoResult<()> { fs_imp::chmod(path, mode.bits() as uint) .update_err("couldn't chmod path", |e| - format!("{}; path={}; mode={}", e, path.display(), mode)) + format!("{}; path={:?}; mode={:?}", e, path.display(), mode)) } /// Change the user and group owners of a file at the specified path. pub fn chown(path: &Path, uid: int, gid: int) -> IoResult<()> { fs_imp::chown(path, uid, gid) .update_err("couldn't chown path", |e| - format!("{}; path={}; uid={}; gid={}", e, path.display(), uid, gid)) + format!("{}; path={:?}; uid={}; gid={}", e, path.display(), uid, gid)) } /// Creates a new hard link on the filesystem. The `dst` path will be a @@ -440,7 +440,7 @@ pub fn chown(path: &Path, uid: int, gid: int) -> IoResult<()> { pub fn link(src: &Path, dst: &Path) -> IoResult<()> { fs_imp::link(src, dst) .update_err("couldn't link path", |e| - format!("{}; src={}; dest={}", e, src.display(), dst.display())) + format!("{}; src={:?}; dest={:?}", e, src.display(), dst.display())) } /// Creates a new symbolic link on the filesystem. The `dst` path will be a @@ -448,7 +448,7 @@ pub fn link(src: &Path, dst: &Path) -> IoResult<()> { pub fn symlink(src: &Path, dst: &Path) -> IoResult<()> { fs_imp::symlink(src, dst) .update_err("couldn't symlink path", |e| - format!("{}; src={}; dest={}", e, src.display(), dst.display())) + format!("{}; src={:?}; dest={:?}", e, src.display(), dst.display())) } /// Reads a symlink, returning the file that the symlink points to. @@ -460,7 +460,7 @@ pub fn symlink(src: &Path, dst: &Path) -> IoResult<()> { pub fn readlink(path: &Path) -> IoResult<Path> { fs_imp::readlink(path) .update_err("couldn't resolve symlink for path", |e| - format!("{}; path={}", e, path.display())) + format!("{}; path={:?}", e, path.display())) } /// Create a new, empty directory at the provided path @@ -483,7 +483,7 @@ pub fn readlink(path: &Path) -> IoResult<Path> { pub fn mkdir(path: &Path, mode: FilePermission) -> IoResult<()> { fs_imp::mkdir(path, mode.bits() as uint) .update_err("couldn't create directory", |e| - format!("{}; path={}; mode={}", e, path.display(), mode)) + format!("{}; path={:?}; mode={:?}", e, path.display(), mode)) } /// Remove an existing, empty directory @@ -505,7 +505,7 @@ pub fn mkdir(path: &Path, mode: FilePermission) -> IoResult<()> { pub fn rmdir(path: &Path) -> IoResult<()> { fs_imp::rmdir(path) .update_err("couldn't remove directory", |e| - format!("{}; path={}", e, path.display())) + format!("{}; path={:?}", e, path.display())) } /// Retrieve a vector containing all entries within a provided directory @@ -545,7 +545,7 @@ pub fn rmdir(path: &Path) -> IoResult<()> { pub fn readdir(path: &Path) -> IoResult<Vec<Path>> { fs_imp::readdir(path) .update_err("couldn't read directory", - |e| format!("{}; path={}", e, path.display())) + |e| format!("{}; path={:?}", e, path.display())) } /// Returns an iterator that will recursively walk the directory structure @@ -555,7 +555,7 @@ pub fn readdir(path: &Path) -> IoResult<Vec<Path>> { pub fn walk_dir(path: &Path) -> IoResult<Directories> { Ok(Directories { stack: try!(readdir(path).update_err("couldn't walk directory", - |e| format!("{}; path={}", e, path.display()))) + |e| format!("{}; path={:?}", e, path.display()))) }) } @@ -605,7 +605,7 @@ pub fn mkdir_recursive(path: &Path, mode: FilePermission) -> IoResult<()> { let result = mkdir(&curpath, mode) .update_err("couldn't recursively mkdir", - |e| format!("{}; path={}", e, path.display())); + |e| format!("{}; path={:?}", e, path.display())); match result { Err(mkdir_err) => { @@ -632,7 +632,7 @@ pub fn rmdir_recursive(path: &Path) -> IoResult<()> { rm_stack.push(path.clone()); fn rmdir_failed(err: &IoError, path: &Path) -> String { - format!("rmdir_recursive failed; path={}; cause={}", + format!("rmdir_recursive failed; path={:?}; cause={}", path.display(), err) } @@ -692,14 +692,14 @@ pub fn rmdir_recursive(path: &Path) -> IoResult<()> { pub fn change_file_times(path: &Path, atime: u64, mtime: u64) -> IoResult<()> { fs_imp::utime(path, atime, mtime) .update_err("couldn't change_file_times", |e| - format!("{}; path={}", e, path.display())) + format!("{}; path={:?}", e, path.display())) } impl Reader for File { fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { fn update_err<T>(result: IoResult<T>, file: &File) -> IoResult<T> { result.update_err("couldn't read file", - |e| format!("{}; path={}", + |e| format!("{}; path={:?}", e, file.path.display())) } @@ -722,7 +722,7 @@ impl Writer for File { fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.fd.write(buf) .update_err("couldn't write to file", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{}; path={:?}", e, self.path.display())) } } @@ -730,7 +730,7 @@ impl Seek for File { fn tell(&self) -> IoResult<u64> { self.fd.tell() .update_err("couldn't retrieve file cursor (`tell`)", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{}; path={:?}", e, self.path.display())) } fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> { @@ -743,7 +743,7 @@ impl Seek for File { Err(e) => Err(e), }; err.update_err("couldn't seek in file", - |e| format!("{}; path={}", e, self.path.display())) + |e| format!("{}; path={:?}", e, self.path.display())) } } @@ -832,13 +832,13 @@ mod test { macro_rules! check { ($e:expr) => ( match $e { Ok(t) => t, - Err(e) => panic!("{} failed with: {}", stringify!($e), e), + Err(e) => panic!("{} failed with: {:?}", stringify!($e), e), } ) } macro_rules! error { ($e:expr, $s:expr) => ( match $e { - Ok(_) => panic!("Unexpected success. Should've been: {}", $s), + Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s), Err(ref err) => assert!(err.to_string().contains($s.as_slice()), format!("`{}` did not contain `{}`", err, $s)) } @@ -889,7 +889,7 @@ mod test { let mut read_buf = [0; 1028]; let read_str = match check!(read_stream.read(&mut read_buf)) { -1|0 => panic!("shouldn't happen"), - n => str::from_utf8(read_buf[..n]).unwrap().to_string() + n => str::from_utf8(read_buf.index(&(0..n))).unwrap().to_string() }; assert_eq!(read_str.as_slice(), message); } @@ -906,7 +906,7 @@ mod test { if cfg!(unix) { error!(result, "no such file or directory"); } - error!(result, format!("path={}; mode=open; access=read", filename.display())); + error!(result, format!("path={:?}; mode=open; access=read", filename.display())); } #[test] @@ -920,7 +920,7 @@ mod test { if cfg!(unix) { error!(result, "no such file or directory"); } - error!(result, format!("path={}", filename.display())); + error!(result, format!("path={:?}", filename.display())); } #[test] @@ -1188,7 +1188,7 @@ mod test { error!(result, "couldn't recursively mkdir"); error!(result, "couldn't create directory"); error!(result, "mode=0700"); - error!(result, format!("path={}", file.display())); + error!(result, format!("path={:?}", file.display())); } #[test] @@ -1255,7 +1255,7 @@ mod test { error!(copy(&from, &to), format!("couldn't copy path (the source path is not an \ - existing file; from={}; to={})", + existing file; from={:?}; to={:?})", from.display(), to.display())); match copy(&from, &to) { diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index 5c17644a1ac..9a6ad04fdbc 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -13,6 +13,7 @@ //! Readers and Writers for in-memory buffers use cmp::min; +use ops::Index; use option::Option::None; use result::Result::{Err, Ok}; use io; @@ -159,7 +160,7 @@ impl Reader for MemReader { let write_len = min(buf.len(), self.buf.len() - self.pos); { - let input = self.buf[self.pos.. self.pos + write_len]; + let input = self.buf.index(&(self.pos.. (self.pos + write_len))); let output = buf.slice_to_mut(write_len); assert_eq!(input.len(), output.len()); slice::bytes::copy_memory(output, input); @@ -187,7 +188,7 @@ impl Buffer for MemReader { #[inline] fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]> { if self.pos < self.buf.len() { - Ok(self.buf[self.pos..]) + Ok(self.buf.index(&(self.pos..))) } else { Err(io::standard_error(io::EndOfFile)) } @@ -204,7 +205,7 @@ impl<'a> Reader for &'a [u8] { let write_len = min(buf.len(), self.len()); { - let input = self[..write_len]; + let input = self.index(&(0..write_len)); let output = buf.slice_to_mut(write_len); slice::bytes::copy_memory(output, input); } @@ -227,7 +228,7 @@ impl<'a> Buffer for &'a [u8] { #[inline] fn consume(&mut self, amt: uint) { - *self = self[amt..]; + *self = self.index(&(amt..)); } } @@ -286,7 +287,7 @@ impl<'a> Writer for BufWriter<'a> { Ok(()) } else { - slice::bytes::copy_memory(dst, src[..dst_len]); + slice::bytes::copy_memory(dst, src.index(&(0..dst_len))); self.pos += dst_len; @@ -349,7 +350,7 @@ impl<'a> Reader for BufReader<'a> { let write_len = min(buf.len(), self.buf.len() - self.pos); { - let input = self.buf[self.pos.. self.pos + write_len]; + let input = self.buf.index(&(self.pos.. (self.pos + write_len))); let output = buf.slice_to_mut(write_len); assert_eq!(input.len(), output.len()); slice::bytes::copy_memory(output, input); @@ -377,7 +378,7 @@ impl<'a> Buffer for BufReader<'a> { #[inline] fn fill_buf(&mut self) -> IoResult<&[u8]> { if self.pos < self.buf.len() { - Ok(self.buf[self.pos..]) + Ok(self.buf.index(&(self.pos..))) } else { Err(io::standard_error(io::EndOfFile)) } @@ -390,9 +391,9 @@ impl<'a> Buffer for BufReader<'a> { #[cfg(test)] mod test { extern crate "test" as test_crate; - use prelude::v1::*; - - use io::{SeekSet, SeekCur, SeekEnd}; + use io::{SeekSet, SeekCur, SeekEnd, Reader, Writer, Seek}; + use prelude::v1::{Ok, Err, range, Vec, Buffer, AsSlice, SliceExt}; + use prelude::v1::{IteratorExt, Index}; use io; use iter::repeat; use self::test_crate::Bencher; @@ -498,7 +499,7 @@ mod test { assert_eq!(buf, b); assert_eq!(reader.read(&mut buf), Ok(3)); let b: &[_] = &[5, 6, 7]; - assert_eq!(buf[0..3], b); + assert_eq!(buf.index(&(0..3)), b); assert!(reader.read(&mut buf).is_err()); let mut reader = MemReader::new(vec!(0, 1, 2, 3, 4, 5, 6, 7)); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); @@ -524,7 +525,7 @@ mod test { assert_eq!(buf.as_slice(), b); assert_eq!(reader.read(&mut buf), Ok(3)); let b: &[_] = &[5, 6, 7]; - assert_eq!(buf[0..3], b); + assert_eq!(buf.index(&(0..3)), b); assert!(reader.read(&mut buf).is_err()); let mut reader = &mut in_buf.as_slice(); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); @@ -551,7 +552,7 @@ mod test { assert_eq!(buf, b); assert_eq!(reader.read(&mut buf), Ok(3)); let b: &[_] = &[5, 6, 7]; - assert_eq!(buf[0..3], b); + assert_eq!(buf.index(&(0..3)), b); assert!(reader.read(&mut buf).is_err()); let mut reader = BufReader::new(in_buf.as_slice()); assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3)); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 5bef473db99..9ef9081bc3c 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -120,10 +120,12 @@ //! for stream in acceptor.incoming() { //! match stream { //! Err(e) => { /* connection failed */ } -//! Ok(stream) => Thread::spawn(move|| { -//! // connection succeeded -//! handle_client(stream) -//! }).detach() +//! Ok(stream) => { +//! Thread::spawn(move|| { +//! // connection succeeded +//! handle_client(stream) +//! }); +//! } //! } //! } //! @@ -232,9 +234,9 @@ use error::{FromError, Error}; use fmt; use int; use iter::{Iterator, IteratorExt}; -use kinds::Sized; +use marker::Sized; use mem::transmute; -use ops::FnOnce; +use ops::{FnOnce, Index}; use option::Option; use option::Option::{Some, None}; use os; @@ -285,8 +287,7 @@ pub mod stdio; pub mod timer; pub mod util; -#[cfg_attr(stage0, macro_escape)] -#[cfg_attr(not(stage0), macro_use)] +#[macro_use] pub mod test; /// The default buffer size for various I/O operations @@ -302,7 +303,7 @@ pub type IoResult<T> = Result<T, IoError>; /// # FIXME /// /// Is something like this sufficient? It's kind of archaic -#[derive(PartialEq, Eq, Clone)] +#[derive(PartialEq, Eq, Clone, Show)] pub struct IoError { /// An enumeration which can be matched against for determining the flavor /// of error. @@ -339,7 +340,7 @@ impl IoError { } } -impl fmt::Show for IoError { +impl fmt::String for IoError { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { IoError { kind: OtherIoError, desc: "unknown error", detail: Some(ref detail) } => @@ -1068,7 +1069,7 @@ pub trait Writer { fn write_char(&mut self, c: char) -> IoResult<()> { let mut buf = [0u8; 4]; let n = c.encode_utf8(buf.as_mut_slice()).unwrap_or(0); - self.write(buf[..n]) + self.write(buf.index(&(0..n))) } /// Write the result of passing n through `int::to_str_bytes`. @@ -1453,7 +1454,7 @@ pub trait Buffer: Reader { }; match available.iter().position(|&b| b == byte) { Some(i) => { - res.push_all(available[..i + 1]); + res.push_all(available.index(&(0..(i + 1)))); used = i + 1; break } @@ -1492,7 +1493,7 @@ pub trait Buffer: Reader { } } } - match str::from_utf8(buf[..width]).ok() { + match str::from_utf8(buf.index(&(0..width))).ok() { Some(s) => Ok(s.char_at(0)), None => Err(standard_error(InvalidInput)) } @@ -1604,6 +1605,7 @@ pub struct IncomingConnections<'a, A: ?Sized +'a> { inc: &'a mut A, } +#[old_impl_check] impl<'a, T, A: ?Sized + Acceptor<T>> Iterator for IncomingConnections<'a, A> { type Item = IoResult<T>; @@ -1656,7 +1658,7 @@ pub fn standard_error(kind: IoErrorKind) -> IoError { /// A mode specifies how a file should be opened or created. These modes are /// passed to `File::open_mode` and are used to control where the file is /// positioned when it is initially opened. -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Show)] pub enum FileMode { /// Opens a file positioned at the beginning. Open, @@ -1668,7 +1670,7 @@ pub enum FileMode { /// Access permissions with which the file should be opened. `File`s /// opened with `Read` will return an error if written to. -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Show)] pub enum FileAccess { /// Read-only access, requests to write will result in an error Read, @@ -1780,9 +1782,11 @@ pub struct UnstableFileStat { pub gen: u64, } + +// NOTE(stage0): change this one last #[doc=..] to /// after the next snapshot bitflags! { - #[doc = "A set of permissions for a file or directory is represented"] - #[doc = "by a set of flags which are or'd together."] + #[doc = "A set of permissions for a file or directory is represented by a set of"] + /// flags which are or'd together. flags FilePermission: u32 { const USER_READ = 0o400, const USER_WRITE = 0o200, @@ -1798,20 +1802,20 @@ bitflags! { const GROUP_RWX = GROUP_READ.bits | GROUP_WRITE.bits | GROUP_EXECUTE.bits, const OTHER_RWX = OTHER_READ.bits | OTHER_WRITE.bits | OTHER_EXECUTE.bits, - #[doc = "Permissions for user owned files, equivalent to 0644 on"] - #[doc = "unix-like systems."] + /// Permissions for user owned files, equivalent to 0644 on unix-like + /// systems. const USER_FILE = USER_READ.bits | USER_WRITE.bits | GROUP_READ.bits | OTHER_READ.bits, - #[doc = "Permissions for user owned directories, equivalent to 0755 on"] - #[doc = "unix-like systems."] + /// Permissions for user owned directories, equivalent to 0755 on + /// unix-like systems. const USER_DIR = USER_RWX.bits | GROUP_READ.bits | GROUP_EXECUTE.bits | OTHER_READ.bits | OTHER_EXECUTE.bits, - #[doc = "Permissions for user owned executables, equivalent to 0755"] - #[doc = "on unix-like systems."] + /// Permissions for user owned executables, equivalent to 0755 + /// on unix-like systems. const USER_EXEC = USER_DIR.bits, - #[doc = "All possible permissions enabled."] + /// All possible permissions enabled. const ALL_PERMISSIONS = USER_RWX.bits | GROUP_RWX.bits | OTHER_RWX.bits, } } @@ -1826,6 +1830,12 @@ impl Default for FilePermission { impl fmt::Show for FilePermission { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl fmt::String for FilePermission { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:04o}", self.bits) } } diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index 24d45dcd652..7825a4e16e1 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -29,7 +29,7 @@ use sys; use vec::Vec; /// Hints to the types of sockets that are desired when looking up hosts -#[derive(Copy)] +#[derive(Copy, Show)] pub enum SocketType { Stream, Datagram, Raw } @@ -38,7 +38,7 @@ pub enum SocketType { /// to manipulate how a query is performed. /// /// The meaning of each of these flags can be found with `man -s 3 getaddrinfo` -#[derive(Copy)] +#[derive(Copy, Show)] pub enum Flag { AddrConfig, All, @@ -51,7 +51,7 @@ pub enum Flag { /// A transport protocol associated with either a hint or a return value of /// `lookup` -#[derive(Copy)] +#[derive(Copy, Show)] pub enum Protocol { TCP, UDP } @@ -61,7 +61,7 @@ pub enum Protocol { /// /// For details on these fields, see their corresponding definitions via /// `man -s 3 getaddrinfo` -#[derive(Copy)] +#[derive(Copy, Show)] pub struct Hint { pub family: uint, pub socktype: Option<SocketType>, @@ -69,7 +69,7 @@ pub struct Hint { pub flags: uint, } -#[derive(Copy)] +#[derive(Copy, Show)] pub struct Info { pub address: SocketAddr, pub family: uint, diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index d398b61fe64..b9f653f86c2 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -22,7 +22,7 @@ use fmt; use io::{self, IoResult, IoError}; use io::net; use iter::{Iterator, IteratorExt}; -use ops::{FnOnce, FnMut}; +use ops::{FnOnce, FnMut, Index}; use option::Option; use option::Option::{None, Some}; use result::Result::{Ok, Err}; @@ -32,13 +32,13 @@ use vec::Vec; pub type Port = u16; -#[derive(Copy, PartialEq, Eq, Clone, Hash)] +#[derive(Copy, PartialEq, Eq, Clone, Hash, Show)] pub enum IpAddr { Ipv4Addr(u8, u8, u8, u8), Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16) } -impl fmt::Show for IpAddr { +impl fmt::String for IpAddr { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match *self { Ipv4Addr(a, b, c, d) => @@ -63,13 +63,13 @@ impl fmt::Show for IpAddr { } } -#[derive(Copy, PartialEq, Eq, Clone, Hash)] +#[derive(Copy, PartialEq, Eq, Clone, Hash, Show)] pub struct SocketAddr { pub ip: IpAddr, pub port: Port, } -impl fmt::Show for SocketAddr { +impl fmt::String for SocketAddr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.ip { Ipv4Addr(..) => write!(f, "{}:{}", self.ip, self.port), @@ -313,7 +313,7 @@ impl<'a> Parser<'a> { let mut tail = [0u16; 8]; let (tail_size, _) = read_groups(self, &mut tail, 8 - head_size); - Some(ipv6_addr_from_head_tail(head[..head_size], tail[..tail_size])) + Some(ipv6_addr_from_head_tail(head.index(&(0..head_size)), tail.index(&(0..tail_size)))) } fn read_ipv6_addr(&mut self) -> Option<IpAddr> { diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/io/net/pipe.rs index 738c70412f7..29295b5751c 100644 --- a/src/libstd/io/net/pipe.rs +++ b/src/libstd/io/net/pipe.rs @@ -608,7 +608,7 @@ mod tests { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv(); - }).detach(); + }); let mut b = [0]; let mut s = UnixStream::connect(&addr).unwrap(); @@ -645,7 +645,7 @@ mod tests { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv(); - }).detach(); + }); let mut s = UnixStream::connect(&addr).unwrap(); let s2 = s.clone(); @@ -672,7 +672,7 @@ mod tests { rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); let _ = rx.recv(); - }).detach(); + }); let mut s = a.accept().unwrap(); s.set_timeout(Some(20)); @@ -716,7 +716,7 @@ mod tests { } } let _ = rx.recv(); - }).detach(); + }); let mut s = a.accept().unwrap(); s.set_read_timeout(Some(20)); @@ -739,7 +739,7 @@ mod tests { rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); let _ = rx.recv(); - }).detach(); + }); let mut s = a.accept().unwrap(); s.set_write_timeout(Some(20)); @@ -766,7 +766,7 @@ mod tests { rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); let _ = rx.recv(); - }).detach(); + }); let mut s = a.accept().unwrap(); let s2 = s.clone(); diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 3e59aaa05ef..7a376b50cd7 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -146,7 +146,7 @@ impl TcpStream { /// timer::sleep(Duration::seconds(1)); /// let mut stream = stream2; /// stream.close_read(); - /// }).detach(); + /// }); /// /// // wait for some data, will get canceled after one second /// let mut buf = [0]; @@ -295,10 +295,12 @@ impl sys_common::AsInner<TcpStreamImp> for TcpStream { /// for stream in acceptor.incoming() { /// match stream { /// Err(e) => { /* connection failed */ } -/// Ok(stream) => Thread::spawn(move|| { -/// // connection succeeded -/// handle_client(stream) -/// }).detach() +/// Ok(stream) => { +/// Thread::spawn(move|| { +/// // connection succeeded +/// handle_client(stream) +/// }); +/// } /// } /// } /// @@ -432,7 +434,7 @@ impl TcpAcceptor { /// Err(e) => panic!("unexpected error: {}", e), /// } /// } - /// }).detach(); + /// }); /// /// # fn wait_for_sigint() {} /// // Now that our accept loop is running, wait for the program to be @@ -660,7 +662,7 @@ mod test { Ok(..) => panic!(), Err(ref e) => { assert!(e.kind == NotConnected || e.kind == EndOfFile, - "unknown kind: {}", e.kind); + "unknown kind: {:?}", e.kind); } } } @@ -684,7 +686,7 @@ mod test { Ok(..) => panic!(), Err(ref e) => { assert!(e.kind == NotConnected || e.kind == EndOfFile, - "unknown kind: {}", e.kind); + "unknown kind: {:?}", e.kind); } } } @@ -997,7 +999,7 @@ mod test { Ok(..) => panic!(), Err(e) => { assert!(e.kind == ConnectionRefused || e.kind == OtherIoError, - "unknown error: {} {}", e, e.kind); + "unknown error: {} {:?}", e, e.kind); } } } @@ -1186,7 +1188,7 @@ mod test { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv().unwrap(); - }).detach(); + }); let mut b = [0]; let mut s = TcpStream::connect(addr).unwrap(); @@ -1223,7 +1225,7 @@ mod test { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv().unwrap(); - }).detach(); + }); let mut s = TcpStream::connect(addr).unwrap(); let s2 = s.clone(); @@ -1250,7 +1252,7 @@ mod test { rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); let _ = rx.recv(); - }).detach(); + }); let mut s = a.accept().unwrap(); s.set_timeout(Some(20)); @@ -1289,7 +1291,7 @@ mod test { } } let _ = rx.recv(); - }).detach(); + }); let mut s = a.accept().unwrap(); s.set_read_timeout(Some(20)); @@ -1312,7 +1314,7 @@ mod test { rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); let _ = rx.recv(); - }).detach(); + }); let mut s = a.accept().unwrap(); s.set_write_timeout(Some(20)); @@ -1340,7 +1342,7 @@ mod test { rx.recv().unwrap(); assert_eq!(s.write(&[0]), Ok(())); let _ = rx.recv(); - }).detach(); + }); let mut s = a.accept().unwrap(); let s2 = s.clone(); diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index ea232ad0c3f..55df6330dd3 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -395,7 +395,14 @@ impl Command { } } +#[cfg(stage0)] impl fmt::Show for Command { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl fmt::String for Command { /// Format the program and arguments of a Command for display. Any /// non-utf8 data is lossily converted using the utf8 replacement /// character. @@ -506,6 +513,14 @@ pub enum ProcessExit { impl fmt::Show for ProcessExit { /// Format a ProcessExit enum, to nicely present the information. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + + +impl fmt::String for ProcessExit { + /// Format a ProcessExit enum, to nicely present the information. + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { ExitStatus(code) => write!(f, "exit code: {}", code), ExitSignal(code) => write!(f, "signal: {}", code), @@ -705,7 +720,7 @@ impl Process { Thread::spawn(move |:| { let mut stream = stream; tx.send(stream.read_to_end()).unwrap(); - }).detach(); + }); } None => tx.send(Ok(Vec::new())).unwrap() } @@ -752,12 +767,12 @@ impl Drop for Process { #[cfg(test)] mod tests { - use prelude::v1::*; - + use io::{Truncate, Write, TimedOut, timer, process, FileNotFound}; + use prelude::v1::{Ok, Err, range, drop, Some, None, Vec}; + use prelude::v1::{Path, String, Reader, Writer, Clone}; + use prelude::v1::{SliceExt, Str, StrExt, AsSlice, ToString, GenericPath}; use io::fs::PathExtensions; - use io::process; use io::timer::*; - use io::{Truncate, Write, TimedOut, timer, FileNotFound}; use rt::running_on_valgrind; use str; use super::{CreatePipe}; diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index f571bed3ba2..9ee2f5705b8 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -34,7 +34,7 @@ use failure::LOCAL_STDERR; use fmt; use io::{Reader, Writer, IoResult, IoError, OtherIoError, Buffer, standard_error, EndOfFile, LineBufferedWriter, BufferedReader}; -use kinds::{Sync, Send}; +use marker::{Sync, Send}; use libc; use mem; use option::Option; @@ -349,7 +349,7 @@ fn with_task_stdout<F>(f: F) where F: FnOnce(&mut Writer) -> IoResult<()> { }); match result { Ok(()) => {} - Err(e) => panic!("failed printing to stdout: {}", e), + Err(e) => panic!("failed printing to stdout: {:?}", e), } } diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index e073f76af82..8a0445be471 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -358,7 +358,7 @@ mod test { Thread::spawn(move|| { let _ = timer_rx.recv(); - }).detach(); + }); // when we drop the TimerWatcher we're going to destroy the channel, // which must wake up the task on the other end @@ -372,7 +372,7 @@ mod test { Thread::spawn(move|| { let _ = timer_rx.recv(); - }).detach(); + }); timer.oneshot(Duration::milliseconds(1)); } @@ -385,7 +385,7 @@ mod test { Thread::spawn(move|| { let _ = timer_rx.recv(); - }).detach(); + }); timer.sleep(Duration::milliseconds(1)); } diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 86fa68d63ac..c0254a3e7a2 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -59,7 +59,7 @@ impl<R: Reader> Reader for LimitReader<R> { impl<R: Buffer> Buffer for LimitReader<R> { fn fill_buf<'a>(&'a mut self) -> io::IoResult<&'a [u8]> { let amt = try!(self.inner.fill_buf()); - let buf = amt[..cmp::min(amt.len(), self.limit)]; + let buf = amt.index(&(0..cmp::min(amt.len(), self.limit))); if buf.len() == 0 { Err(io::standard_error(io::EndOfFile)) } else { @@ -220,7 +220,7 @@ impl<R: Reader, W: Writer> TeeReader<R, W> { impl<R: Reader, W: Writer> Reader for TeeReader<R, W> { fn read(&mut self, buf: &mut [u8]) -> io::IoResult<uint> { self.reader.read(buf).and_then(|len| { - self.writer.write(buf[mut ..len]).map(|()| len) + self.writer.write(buf.index_mut(&(0..len))).map(|()| len) }) } } @@ -234,7 +234,7 @@ pub fn copy<R: Reader, W: Writer>(r: &mut R, w: &mut W) -> io::IoResult<()> { Err(ref e) if e.kind == io::EndOfFile => return Ok(()), Err(e) => return Err(e), }; - try!(w.write(buf[..len])); + try!(w.write(buf.index(&(0..len)))); } } |
