Move from old_io to std::io

Bump to 0.2.0
diff --git a/Cargo.toml b/Cargo.toml
index b1fea9c..9f42ae0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 
 name = "rand"
-version = "0.1.4"
+version = "0.2.0"
 authors = ["The Rust Project Developers"]
 license = "MIT/Apache-2.0"
 readme = "README.md"
diff --git a/src/lib.rs b/src/lib.rs
index 03840ac..56bb0b6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -10,10 +10,11 @@
 
 //! Utilities for random number generation
 //!
-//! The key functions are `random()` and `Rng::gen()`. These are polymorphic
-//! and so can be used to generate any type that implements `Rand`. Type inference
+//! The key functions are `random()` and `Rng::gen()`. These are polymorphic and
+//! so can be used to generate any type that implements `Rand`. Type inference
 //! means that often a simple call to `rand::random()` or `rng.gen()` will
-//! suffice, but sometimes an annotation is required, e.g. `rand::random::<f64>()`.
+//! suffice, but sometimes an annotation is required, e.g.
+//! `rand::random::<f64>()`.
 //!
 //! See the `distributions` submodule for sampling random numbers from
 //! distributions like normal and exponential.
@@ -31,7 +32,8 @@
 //!
 //! An application that requires an entropy source for cryptographic purposes
 //! must use `OsRng`, which reads randomness from the source that the operating
-//! system provides (e.g. `/dev/urandom` on Unixes or `CryptGenRandom()` on Windows).
+//! system provides (e.g. `/dev/urandom` on Unixes or `CryptGenRandom()` on
+//! Windows).
 //! The other random number generators provided by this module are not suitable
 //! for such purposes.
 //!
@@ -52,7 +54,7 @@
 //!     available, and use `/dev/urandom` fallback if not.  If an application
 //!     does not have `getrandom` and likely to be run soon after first booting,
 //!     or on a system with very few entropy sources, one should consider using
-//!     `/dev/random` via `ReaderRng`.
+//!     `/dev/random` via `ReadRng`.
 //! -   On some systems (e.g. FreeBSD, OpenBSD and Mac OS X) there is no
 //!     difference between the two sources. (Also note that, on some systems
 //!     e.g.  FreeBSD, both `/dev/random` and `/dev/urandom` may block once if
@@ -119,10 +121,10 @@
 //! This is a simulation of the [Monty Hall Problem][]:
 //!
 //! > Suppose you're on a game show, and you're given the choice of three doors:
-//! > Behind one door is a car; behind the others, goats. You pick a door, say No. 1,
-//! > and the host, who knows what's behind the doors, opens another door, say No. 3,
-//! > which has a goat. He then says to you, "Do you want to pick door No. 2?"
-//! > Is it to your advantage to switch your choice?
+//! > Behind one door is a car; behind the others, goats. You pick a door, say
+//! > No. 1, and the host, who knows what's behind the doors, opens another
+//! > door, say No. 3, which has a goat. He then says to you, "Do you want to
+//! > pick door No. 2?" Is it to your advantage to switch your choice?
 //!
 //! The rather unintuitive answer is that you will have a 2/3 chance of winning
 //! if you switch and a 1/3 chance of winning if you don't, so it's better to
@@ -143,7 +145,8 @@
 //! }
 //!
 //! // Run a single simulation of the Monty Hall problem.
-//! fn simulate<R: Rng>(random_door: &Range<usize>, rng: &mut R) -> SimulationResult {
+//! fn simulate<R: Rng>(random_door: &Range<usize>, rng: &mut R)
+//!                     -> SimulationResult {
 //!     let car = random_door.ind_sample(rng);
 //!
 //!     // This is our initial choice
@@ -221,9 +224,10 @@
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
        html_root_url = "http://doc.rust-lang.org/rand/")]
-#![feature(core, os, old_path, old_io)]
+#![feature(core, os, old_path, io, fs)]
 
 #![cfg_attr(test, feature(test))]
+#![cfg_attr(test, deny(warnings))]
 
 extern crate core;
 #[cfg(test)] #[macro_use] extern crate log;
@@ -231,7 +235,7 @@
 use std::cell::RefCell;
 use std::marker;
 use std::mem;
-use std::old_io::IoResult;
+use std::io;
 use std::rc::Rc;
 use std::num::wrapping::Wrapping as w;
 
@@ -254,7 +258,7 @@
 pub mod reseeding;
 mod rand_impls;
 pub mod os;
-pub mod reader;
+pub mod read;
 
 #[allow(bad_style)]
 type w64 = w<u64>;
@@ -721,8 +725,8 @@
     /// appropriate.
     ///
     /// Reading the randomness from the OS may fail, and any error is
-    /// propagated via the `IoResult` return value.
-    pub fn new() -> IoResult<StdRng> {
+    /// propagated via the `io::Result` return value.
+    pub fn new() -> io::Result<StdRng> {
         OsRng::new().map(|mut r| StdRng { rng: r.gen() })
     }
 }
diff --git a/src/os.rs b/src/os.rs
index 3e1959c..9159fe2 100644
--- a/src/os.rs
+++ b/src/os.rs
@@ -19,9 +19,10 @@
 
     use self::OsRngInner::*;
 
-    use std::old_io::{IoResult, File};
+    use std::io;
+    use std::fs::File;
     use Rng;
-    use reader::ReaderRng;
+    use read::ReadRng;
     use std::mem;
     use std::os::errno;
 
@@ -141,20 +142,20 @@
 
     enum OsRngInner {
         OsGetrandomRng,
-        OsReaderRng(ReaderRng<File>),
+        OsReadRng(ReadRng<File>),
     }
 
     impl OsRng {
         /// Create a new `OsRng`.
-        pub fn new() -> IoResult<OsRng> {
+        pub fn new() -> io::Result<OsRng> {
             if is_getrandom_available() {
                 return Ok(OsRng { inner: OsGetrandomRng });
             }
 
             let reader = try!(File::open(&Path::new("/dev/urandom")));
-            let reader_rng = ReaderRng::new(reader);
+            let reader_rng = ReadRng::new(reader);
 
-            Ok(OsRng { inner: OsReaderRng(reader_rng) })
+            Ok(OsRng { inner: OsReadRng(reader_rng) })
         }
     }
 
@@ -162,19 +163,19 @@
         fn next_u32(&mut self) -> u32 {
             match self.inner {
                 OsGetrandomRng => getrandom_next_u32(),
-                OsReaderRng(ref mut rng) => rng.next_u32(),
+                OsReadRng(ref mut rng) => rng.next_u32(),
             }
         }
         fn next_u64(&mut self) -> u64 {
             match self.inner {
                 OsGetrandomRng => getrandom_next_u64(),
-                OsReaderRng(ref mut rng) => rng.next_u64(),
+                OsReadRng(ref mut rng) => rng.next_u64(),
             }
         }
         fn fill_bytes(&mut self, v: &mut [u8]) {
             match self.inner {
                 OsGetrandomRng => getrandom_fill_bytes(v),
-                OsReaderRng(ref mut rng) => rng.fill_bytes(v)
+                OsReadRng(ref mut rng) => rng.fill_bytes(v)
             }
         }
     }
@@ -184,7 +185,7 @@
 mod imp {
     extern crate libc;
 
-    use std::old_io::{IoResult};
+    use std::io;
     use std::marker::Sync;
     use std::mem;
     use std::os;
@@ -223,7 +224,7 @@
 
     impl OsRng {
         /// Create a new `OsRng`.
-        pub fn new() -> IoResult<OsRng> {
+        pub fn new() -> io::Result<OsRng> {
             Ok(OsRng { _dummy: () })
         }
     }
@@ -254,7 +255,7 @@
 mod imp {
     extern crate libc;
 
-    use std::old_io::{IoResult, IoError};
+    use std::io;
     use std::mem;
     use std::ops::Drop;
     use std::os;
@@ -297,7 +298,7 @@
 
     impl OsRng {
         /// Create a new `OsRng`.
-        pub fn new() -> IoResult<OsRng> {
+        pub fn new() -> io::Result<OsRng> {
             let mut hcp = 0;
             let ret = unsafe {
                 CryptAcquireContextA(&mut hcp, 0 as LPCSTR, 0 as LPCSTR,
@@ -306,7 +307,7 @@
             };
 
             if ret == 0 {
-                Err(IoError::last_error())
+                Err(io::Error::last_os_error())
             } else {
                 Ok(OsRng { hcryptprov: hcp })
             }
diff --git a/src/reader.rs b/src/read.rs
similarity index 63%
rename from src/reader.rs
rename to src/read.rs
index bc60eca..cc5f386 100644
--- a/src/reader.rs
+++ b/src/read.rs
@@ -8,12 +8,13 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-//! A wrapper around any Reader to treat it as an RNG.
+//! A wrapper around any Read to treat it as an RNG.
 
-use std::old_io::Reader;
+use std::io::{self, Read};
+use std::mem;
 use Rng;
 
-/// An RNG that reads random bytes straight from a `Reader`. This will
+/// An RNG that reads random bytes straight from a `Read`. This will
 /// work best with an infinite reader, but this is not required.
 ///
 /// # Panics
@@ -23,57 +24,60 @@
 /// # Example
 ///
 /// ```rust
-/// use rand::{reader, Rng};
-/// use std::old_io::MemReader;
+/// use rand::{read, Rng};
 ///
-/// let mut rng = reader::ReaderRng::new(MemReader::new(vec!(1,2,3,4,5,6,7,8)));
+/// let data = vec![1, 2, 3, 4, 5, 6, 7, 8];
+/// let mut rng = read::ReadRng::new(&data[..]);
 /// println!("{:x}", rng.gen::<u32>());
 /// ```
-pub struct ReaderRng<R> {
+pub struct ReadRng<R> {
     reader: R
 }
 
-impl<R: Reader> ReaderRng<R> {
-    /// Create a new `ReaderRng` from a `Reader`.
-    pub fn new(r: R) -> ReaderRng<R> {
-        ReaderRng {
+impl<R: Read> ReadRng<R> {
+    /// Create a new `ReadRng` from a `Read`.
+    pub fn new(r: R) -> ReadRng<R> {
+        ReadRng {
             reader: r
         }
     }
 }
 
-impl<R: Reader> Rng for ReaderRng<R> {
+impl<R: Read> Rng for ReadRng<R> {
     fn next_u32(&mut self) -> u32 {
         // This is designed for speed: reading a LE integer on a LE
         // platform just involves blitting the bytes into the memory
         // of the u32, similarly for BE on BE; avoiding byteswapping.
-        if cfg!(target_endian="little") {
-            self.reader.read_le_u32().unwrap()
-        } else {
-            self.reader.read_be_u32().unwrap()
-        }
+        let mut buf = [0; 4];
+        fill(&mut self.reader, &mut buf).unwrap();
+        unsafe { *(buf.as_ptr() as *const u32) }
     }
     fn next_u64(&mut self) -> u64 {
         // see above for explanation.
-        if cfg!(target_endian="little") {
-            self.reader.read_le_u64().unwrap()
-        } else {
-            self.reader.read_be_u64().unwrap()
-        }
+        let mut buf = [0; 8];
+        fill(&mut self.reader, &mut buf).unwrap();
+        unsafe { *(buf.as_ptr() as *const u64) }
     }
     fn fill_bytes(&mut self, v: &mut [u8]) {
         if v.len() == 0 { return }
-        match self.reader.read_at_least(v.len(), v) {
-            Ok(_) => {}
-            Err(e) => panic!("ReaderRng.fill_bytes error: {:?}", e)
+        fill(&mut self.reader, v).unwrap();
+    }
+}
+
+fn fill(r: &mut Read, mut buf: &mut [u8]) -> io::Result<()> {
+    while buf.len() > 0 {
+        match try!(r.read(buf)) {
+            0 => return Err(io::Error::new(io::ErrorKind::Other,
+                                           "end of file reached", None)),
+            n => buf = &mut mem::replace(&mut buf, &mut [])[n..],
         }
     }
+    Ok(())
 }
 
 #[cfg(test)]
 mod test {
-    use super::ReaderRng;
-    use std::old_io::MemReader;
+    use super::ReadRng;
     use std::num::Int;
     use Rng;
 
@@ -83,7 +87,7 @@
         let v = vec![0u8, 0, 0, 0, 0, 0, 0, 1,
                      0  , 0, 0, 0, 0, 0, 0, 2,
                      0,   0, 0, 0, 0, 0, 0, 3];
-        let mut rng = ReaderRng::new(MemReader::new(v));
+        let mut rng = ReadRng::new(&v[..]);
 
         assert_eq!(rng.next_u64(), 1_u64.to_be());
         assert_eq!(rng.next_u64(), 2_u64.to_be());
@@ -92,7 +96,7 @@
     #[test]
     fn test_reader_rng_u32() {
         let v = vec![0u8, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3];
-        let mut rng = ReaderRng::new(MemReader::new(v));
+        let mut rng = ReadRng::new(&v[..]);
 
         assert_eq!(rng.next_u32(), 1_u32.to_be());
         assert_eq!(rng.next_u32(), 2_u32.to_be());
@@ -103,7 +107,7 @@
         let v = [1u8, 2, 3, 4, 5, 6, 7, 8];
         let mut w = [0u8; 8];
 
-        let mut rng = ReaderRng::new(MemReader::new(v.to_vec()));
+        let mut rng = ReadRng::new(&v[..]);
         rng.fill_bytes(&mut w);
 
         assert!(v == w);
@@ -112,7 +116,7 @@
     #[test]
     #[should_fail]
     fn test_reader_rng_insufficient_bytes() {
-        let mut rng = ReaderRng::new(MemReader::new(vec!()));
+        let mut rng = ReadRng::new(&[][..]);
         let mut v = [0u8; 3];
         rng.fill_bytes(&mut v);
     }