Skip to content

Commit

Permalink
fix(rustup): update io import, Writer::write
Browse files Browse the repository at this point in the history
Make it build with the latest rust-nightly (2015-01-27)

Renamed io import to old_io.
Renamed Writer::write to Writer::write_all
  • Loading branch information
Christian Stefanescu authored and seanmonstar committed Jan 28, 2015
1 parent 537d691 commit f606b60
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 81 deletions.
4 changes: 2 additions & 2 deletions benches/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate hyper;
extern crate test;

use std::fmt;
use std::io::net::ip::Ipv4Addr;
use std::old_io::net::ip::Ipv4Addr;
use hyper::server::{Request, Response, Server};
use hyper::header::Headers;
use hyper::Client;
Expand All @@ -26,7 +26,7 @@ macro_rules! try_return(
fn handle(_r: Request, res: Response) {
static BODY: &'static [u8] = b"Benchmarking hyper vs others!";
let mut res = try_return!(res.start());
try_return!(res.write(BODY));
try_return!(res.write_all(BODY));
try_return!(res.end());
}

Expand Down
6 changes: 3 additions & 3 deletions benches/client_mock_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ extern crate hyper;
extern crate test;

use std::fmt;
use std::io::{IoResult, MemReader};
use std::io::net::ip::SocketAddr;
use std::old_io::{IoResult, MemReader};
use std::old_io::net::ip::SocketAddr;

use hyper::net;

Expand Down Expand Up @@ -40,7 +40,7 @@ impl Reader for MockStream {
}

impl Writer for MockStream {
fn write(&mut self, _msg: &[u8]) -> IoResult<()> {
fn write_all(&mut self, _msg: &[u8]) -> IoResult<()> {
// we're mocking, what do we care.
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions benches/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate hyper;
extern crate test;

use test::Bencher;
use std::io::net::ip::Ipv4Addr;
use std::old_io::net::ip::Ipv4Addr;

use hyper::method::Method::Get;
use hyper::server::{Request, Response};
Expand All @@ -17,7 +17,7 @@ fn request(url: hyper::Url) {

fn hyper_handle(_: Request, res: Response) {
let mut res = res.start().unwrap();
res.write(PHRASE).unwrap();
res.write_all(PHRASE).unwrap();
res.end().unwrap();
}

Expand Down
4 changes: 2 additions & 2 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
extern crate hyper;

use std::os;
use std::io::stdout;
use std::io::util::copy;
use std::old_io::stdout;
use std::old_io::util::copy;

use hyper::Client;

Expand Down
4 changes: 2 additions & 2 deletions examples/hello.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![allow(unstable)]
extern crate hyper;

use std::io::net::ip::Ipv4Addr;
use std::old_io::net::ip::Ipv4Addr;
use hyper::server::{Request, Response};

static PHRASE: &'static [u8] = b"Hello World!";

fn hello(_: Request, res: Response) {
let mut res = res.start().unwrap();
res.write(PHRASE).unwrap();
res.write_all(PHRASE).unwrap();
res.end().unwrap();
}

Expand Down
6 changes: 3 additions & 3 deletions examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
extern crate hyper;
#[macro_use] extern crate log;

use std::io::util::copy;
use std::io::net::ip::Ipv4Addr;
use std::old_io::util::copy;
use std::old_io::net::ip::Ipv4Addr;

use hyper::{Get, Post};
use hyper::header::ContentLength;
Expand All @@ -27,7 +27,7 @@ fn echo(mut req: Request, mut res: Response) {

res.headers_mut().set(ContentLength(out.len() as u64));
let mut res = try_return!(res.start());
try_return!(res.write(out));
try_return!(res.write_all(out));
try_return!(res.end());
return;
},
Expand Down
4 changes: 2 additions & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
//! to the `status`, the `headers`, and the response body via the `Writer`
//! trait.
use std::default::Default;
use std::io::IoResult;
use std::io::util::copy;
use std::old_io::IoResult;
use std::old_io::util::copy;
use std::iter::Extend;

use url::UrlParser;
Expand Down
6 changes: 3 additions & 3 deletions src/client/request.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Client Requests
use std::io::{BufferedWriter, IoResult};
use std::old_io::{BufferedWriter, IoResult};

use url::Url;

Expand Down Expand Up @@ -157,8 +157,8 @@ impl Request<Streaming> {

impl Writer for Request<Streaming> {
#[inline]
fn write(&mut self, msg: &[u8]) -> IoResult<()> {
self.body.write(msg)
fn write_all(&mut self, msg: &[u8]) -> IoResult<()> {
self.body.write_all(msg)
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/client/response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Client Responses
use std::num::FromPrimitive;
use std::io::{BufferedReader, IoResult};
use std::old_io::{BufferedReader, IoResult};

use header;
use header::{ContentLength, TransferEncoding};
Expand Down Expand Up @@ -97,7 +97,7 @@ impl Reader for Response {
mod tests {
use std::borrow::Cow::Borrowed;
use std::boxed::BoxAny;
use std::io::BufferedReader;
use std::old_io::BufferedReader;

use header::Headers;
use header::TransferEncoding;
Expand Down
2 changes: 1 addition & 1 deletion src/header/common/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl FromStr for Basic {

#[cfg(test)]
mod tests {
use std::io::MemReader;
use std::old_io::MemReader;
use super::{Authorization, Basic};
use super::super::super::{Headers};

Expand Down
2 changes: 1 addition & 1 deletion src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl<'a, H: HeaderFormat> fmt::Debug for HeaderFormatter<'a, H> {

#[cfg(test)]
mod tests {
use std::io::MemReader;
use std::old_io::MemReader;
use std::fmt;
use std::borrow::Cow::Borrowed;
use std::hash::{SipHasher, hash};
Expand Down
64 changes: 32 additions & 32 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::borrow::Cow::{Borrowed, Owned};
use std::borrow::IntoCow;
use std::cmp::min;
use std::io::{self, Reader, IoResult, BufWriter};
use std::old_io::{self, Reader, IoResult, BufWriter};
use std::num::from_u16;
use std::str::{self, FromStr};
use std::string::CowString;
Expand Down Expand Up @@ -72,7 +72,7 @@ impl<R: Reader> Reader for HttpReader<R> {
SizedReader(ref mut body, ref mut remaining) => {
debug!("Sized read, remaining={:?}", remaining);
if *remaining == 0 {
Err(io::standard_error(io::EndOfFile))
Err(old_io::standard_error(old_io::EndOfFile))
} else {
let num = try!(body.read(buf)) as u64;
if num > *remaining {
Expand All @@ -98,7 +98,7 @@ impl<R: Reader> Reader for HttpReader<R> {
// if the 0 digit was missing from the stream, it would
// be an InvalidInput error instead.
debug!("end of chunked");
return Err(io::standard_error(io::EndOfFile));
return Err(old_io::standard_error(old_io::EndOfFile));
}

let to_read = min(rem as usize, buf.len());
Expand All @@ -116,7 +116,7 @@ impl<R: Reader> Reader for HttpReader<R> {
EofReader(ref mut body) => {
body.read(buf)
},
EmptyReader(_) => Err(io::standard_error(io::EndOfFile))
EmptyReader(_) => Err(old_io::standard_error(old_io::EndOfFile))
}
}
}
Expand All @@ -125,7 +125,7 @@ fn eat<R: Reader>(rdr: &mut R, bytes: &[u8]) -> IoResult<()> {
for &b in bytes.iter() {
match try!(rdr.read_byte()) {
byte if byte == b => (),
_ => return Err(io::standard_error(io::InvalidInput))
_ => return Err(old_io::standard_error(old_io::InvalidInput))
}
}
Ok(())
Expand Down Expand Up @@ -154,7 +154,7 @@ fn read_chunk_size<R: Reader>(rdr: &mut R) -> IoResult<u64> {
CR => {
match try!(rdr.read_byte()) {
LF => break,
_ => return Err(io::standard_error(io::InvalidInput))
_ => return Err(old_io::standard_error(old_io::InvalidInput))
}
},
// If we weren't in the extension yet, the ";" signals its start
Expand All @@ -178,7 +178,7 @@ fn read_chunk_size<R: Reader>(rdr: &mut R) -> IoResult<u64> {
// Finally, if we aren't in the extension and we're reading any
// other octet, the chunk size line is invalid!
_ => {
return Err(io::standard_error(io::InvalidInput));
return Err(old_io::standard_error(old_io::InvalidInput));
}
}
}
Expand Down Expand Up @@ -239,47 +239,47 @@ impl<W: Writer> HttpWriter<W> {

/// Ends the HttpWriter, and returns the underlying Writer.
///
/// A final `write()` is called with an empty message, and then flushed.
/// A final `write_all()` is called with an empty message, and then flushed.
/// The ChunkedWriter variant will use this to write the 0-sized last-chunk.
#[inline]
pub fn end(mut self) -> IoResult<W> {
try!(self.write(&[]));
try!(self.write_all(&[]));
try!(self.flush());
Ok(self.unwrap())
}
}

impl<W: Writer> Writer for HttpWriter<W> {
#[inline]
fn write(&mut self, msg: &[u8]) -> IoResult<()> {
fn write_all(&mut self, msg: &[u8]) -> IoResult<()> {
match *self {
ThroughWriter(ref mut w) => w.write(msg),
ThroughWriter(ref mut w) => w.write_all(msg),
ChunkedWriter(ref mut w) => {
let chunk_size = msg.len();
debug!("chunked write, size = {:?}", chunk_size);
try!(write!(w, "{:X}{}", chunk_size, LINE_ENDING));
try!(w.write(msg));
try!(w.write_all(msg));
w.write_str(LINE_ENDING)
},
SizedWriter(ref mut w, ref mut remaining) => {
let len = msg.len() as u64;
if len > *remaining {
let len = *remaining;
*remaining = 0;
try!(w.write(&msg[..len as usize]));
Err(io::standard_error(io::ShortWrite(len as usize)))
try!(w.write_all(&msg[..len as usize]));
Err(old_io::standard_error(old_io::ShortWrite(len as usize)))
} else {
*remaining -= len;
w.write(msg)
w.write_all(msg)
}
},
EmptyWriter(..) => {
let bytes = msg.len();
if bytes == 0 {
Ok(())
} else {
Err(io::IoError {
kind: io::ShortWrite(bytes),
Err(old_io::IoError {
kind: old_io::ShortWrite(bytes),
desc: "EmptyWriter cannot write any bytes",
detail: Some("Cannot include a body with this kind of message".to_string())
})
Expand Down Expand Up @@ -347,7 +347,7 @@ pub fn is_token(b: u8) -> bool {
///
/// The remaining contents of `buf` are left untouched.
fn read_token_until_space<R: Reader>(stream: &mut R, buf: &mut [u8]) -> HttpResult<bool> {
use std::io::BufWriter;
use std::old_io::BufWriter;
let mut bufwrt = BufWriter::new(buf);

loop {
Expand Down Expand Up @@ -697,7 +697,7 @@ fn expect(r: IoResult<u8>, expected: u8) -> HttpResult<()> {

#[cfg(test)]
mod tests {
use std::io::{self, MemReader, MemWriter, IoResult};
use std::old_io::{self, MemReader, MemWriter, IoResult};
use std::borrow::Cow::{Borrowed, Owned};
use test::Bencher;
use uri::RequestUri;
Expand Down Expand Up @@ -800,8 +800,8 @@ mod tests {
fn test_write_chunked() {
use std::str::from_utf8;
let mut w = super::HttpWriter::ChunkedWriter(MemWriter::new());
w.write(b"foo bar").unwrap();
w.write(b"baz quux herp").unwrap();
w.write_all(b"foo bar").unwrap();
w.write_all(b"baz quux herp").unwrap();
let buf = w.end().unwrap().into_inner();
let s = from_utf8(buf.as_slice()).unwrap();
assert_eq!(s, "7\r\nfoo bar\r\nD\r\nbaz quux herp\r\n0\r\n\r\n");
Expand All @@ -811,8 +811,8 @@ mod tests {
fn test_write_sized() {
use std::str::from_utf8;
let mut w = super::HttpWriter::SizedWriter(MemWriter::new(), 8);
w.write(b"foo bar").unwrap();
assert_eq!(w.write(b"baz"), Err(io::standard_error(io::ShortWrite(1))));
w.write_all(b"foo bar").unwrap();
assert_eq!(w.write_all(b"baz"), Err(old_io::standard_error(old_io::ShortWrite(1))));

let buf = w.end().unwrap().into_inner();
let s = from_utf8(buf.as_slice()).unwrap();
Expand All @@ -834,13 +834,13 @@ mod tests {
read("Ff\r\n", Ok(255));
read("Ff \r\n", Ok(255));
// Missing LF or CRLF
read("F\rF", Err(io::standard_error(io::InvalidInput)));
read("F", Err(io::standard_error(io::EndOfFile)));
read("F\rF", Err(old_io::standard_error(old_io::InvalidInput)));
read("F", Err(old_io::standard_error(old_io::EndOfFile)));
// Invalid hex digit
read("X\r\n", Err(io::standard_error(io::InvalidInput)));
read("1X\r\n", Err(io::standard_error(io::InvalidInput)));
read("-\r\n", Err(io::standard_error(io::InvalidInput)));
read("-1\r\n", Err(io::standard_error(io::InvalidInput)));
read("X\r\n", Err(old_io::standard_error(old_io::InvalidInput)));
read("1X\r\n", Err(old_io::standard_error(old_io::InvalidInput)));
read("-\r\n", Err(old_io::standard_error(old_io::InvalidInput)));
read("-1\r\n", Err(old_io::standard_error(old_io::InvalidInput)));
// Acceptable (if not fully valid) extensions do not influence the size
read("1;extension\r\n", Ok(1));
read("a;ext name=value\r\n", Ok(10));
Expand All @@ -851,9 +851,9 @@ mod tests {
read("3 ;\r\n", Ok(3));
read("3 ; \r\n", Ok(3));
// Invalid extensions cause an error
read("1 invalid extension\r\n", Err(io::standard_error(io::InvalidInput)));
read("1 A\r\n", Err(io::standard_error(io::InvalidInput)));
read("1;no CRLF", Err(io::standard_error(io::EndOfFile)));
read("1 invalid extension\r\n", Err(old_io::standard_error(old_io::InvalidInput)));
read("1 A\r\n", Err(old_io::standard_error(old_io::InvalidInput)));
read("1;no CRLF", Err(old_io::standard_error(old_io::EndOfFile)));
}

#[bench]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ extern crate cookie;
extern crate mucell;
extern crate unicase;

pub use std::io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr, Port};
pub use std::old_io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr, Port};
pub use mimewrapper::mime;
pub use url::Url;
pub use client::Client;
Expand All @@ -146,7 +146,7 @@ pub use server::Server;

use std::error::{Error, FromError};
use std::fmt;
use std::io::IoError;
use std::old_io::IoError;

use self::HttpError::{HttpMethodError, HttpUriError, HttpVersionError,
HttpHeaderError, HttpStatusError, HttpIoError};
Expand Down
Loading

0 comments on commit f606b60

Please sign in to comment.