Skip to content

Commit 4026ec1

Browse files
committed
Merge pull request #232 from cyderize/rustup
Update for latest Rust nightly
2 parents 241ebc1 + d9c657d commit 4026ec1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+309
-205
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ url = "*"
1515
openssl = "*"
1616
mime = "*"
1717
unsafe-any = "*"
18-
typeable = "*"
1918
cookie = "*"
2019
time = "*"
2120
mucell = "*"

benches/client_mock_tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::path::BytesContainer;
1212

1313
use hyper::net;
1414

15-
static README: &'static [u8] = include_bin!("../README.md");
15+
static README: &'static [u8] = include_bytes!("../README.md");
1616

1717

1818
struct MockStream {

examples/client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ fn main() {
2222

2323
let mut res = match client.get(url).send() {
2424
Ok(res) => res,
25-
Err(err) => panic!("Failed to connect: {}", err)
25+
Err(err) => panic!("Failed to connect: {:?}", err)
2626
};
2727

2828
println!("Response: {}", res.status);
2929
println!("Headers:\n{}", res.headers);
3030
match copy(&mut res, &mut stdout()) {
3131
Ok(..) => (),
32-
Err(e) => panic!("Stream failure: {}", e)
32+
Err(e) => panic!("Stream failure: {:?}", e)
3333
};
3434

3535
}

src/client/mod.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl Client<HttpConnector> {
6363

6464
}
6565

66+
#[old_impl_check]
6667
impl<C: NetworkConnector<S>, S: NetworkStream> Client<C> {
6768

6869
/// Create a new client with a specific connector.
@@ -162,7 +163,7 @@ impl<'a, U: IntoUrl, C: NetworkConnector<S>, S: NetworkStream> RequestBuilder<'a
162163
pub fn send(self) -> HttpResult<Response> {
163164
let RequestBuilder { client, method, url, headers, body } = self;
164165
let mut url = try!(url.into_url());
165-
debug!("client.request {} {}", method, url);
166+
debug!("client.request {:?} {:?}", method, url);
166167

167168
let can_have_body = match &method {
168169
&Method::Get | &Method::Head => false,
@@ -193,13 +194,13 @@ impl<'a, U: IntoUrl, C: NetworkConnector<S>, S: NetworkStream> RequestBuilder<'a
193194
if res.status.class() != Redirection {
194195
return Ok(res)
195196
}
196-
debug!("redirect code {} for {}", res.status, url);
197+
debug!("redirect code {:?} for {:?}", res.status, url);
197198

198199
let loc = {
199200
// punching borrowck here
200201
let loc = match res.headers.get::<Location>() {
201202
Some(&Location(ref loc)) => {
202-
Some(UrlParser::new().base_url(&url).parse(loc[]))
203+
Some(UrlParser::new().base_url(&url).parse(&loc[]))
203204
}
204205
None => {
205206
debug!("no Location header");
@@ -217,7 +218,7 @@ impl<'a, U: IntoUrl, C: NetworkConnector<S>, S: NetworkStream> RequestBuilder<'a
217218
inspect!("Location", u)
218219
},
219220
Err(e) => {
220-
debug!("Location header had invalid URI: {}", e);
221+
debug!("Location header had invalid URI: {:?}", e);
221222
return Ok(res);
222223
}
223224
};
@@ -242,13 +243,13 @@ pub enum Body<'a> {
242243
/// A Reader does not necessarily know it's size, so it is chunked.
243244
ChunkedBody(&'a mut (Reader + 'a)),
244245
/// For Readers that can know their size, like a `File`.
245-
SizedBody(&'a mut (Reader + 'a), uint),
246+
SizedBody(&'a mut (Reader + 'a), usize),
246247
/// A String has a size, and uses Content-Length.
247-
BufBody(&'a [u8] , uint),
248+
BufBody(&'a [u8] , usize),
248249
}
249250

250251
impl<'a> Body<'a> {
251-
fn size(&self) -> Option<uint> {
252+
fn size(&self) -> Option<usize> {
252253
match *self {
253254
Body::SizedBody(_, len) | Body::BufBody(_, len) => Some(len),
254255
_ => None
@@ -258,7 +259,7 @@ impl<'a> Body<'a> {
258259

259260
impl<'a> Reader for Body<'a> {
260261
#[inline]
261-
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
262+
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
262263
match *self {
263264
Body::ChunkedBody(ref mut r) => r.read(buf),
264265
Body::SizedBody(ref mut r, _) => r.read(buf),
@@ -343,12 +344,12 @@ fn get_host_and_port(url: &Url) -> HttpResult<(String, Port)> {
343344
Some(host) => host,
344345
None => return Err(HttpUriError(UrlError::EmptyHost))
345346
};
346-
debug!("host={}", host);
347+
debug!("host={:?}", host);
347348
let port = match url.port_or_default() {
348349
Some(port) => port,
349350
None => return Err(HttpUriError(UrlError::InvalidPort))
350351
};
351-
debug!("port={}", port);
352+
debug!("port={:?}", port);
352353
Ok((host, port))
353354
}
354355

src/client/request.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ impl Request<Fresh> {
4747

4848
/// Create a new client request with a specific underlying NetworkStream.
4949
pub fn with_connector<C: NetworkConnector<S>, S: NetworkStream>(method: method::Method, url: Url, connector: &mut C) -> HttpResult<Request<Fresh>> {
50-
debug!("{} {}", method, url);
50+
debug!("{:?} {:?}", method, url);
5151
let (host, port) = try!(get_host_and_port(&url));
5252

53-
let stream: S = try!(connector.connect(host[], port, &*url.scheme));
53+
let stream: S = try!(connector.connect(&host[], port, &*url.scheme));
5454
let stream = ThroughWriter(BufferedWriter::new(box stream as Box<NetworkStream + Send>));
5555

5656
let mut headers = Headers::new();
@@ -110,17 +110,17 @@ impl Request<Fresh> {
110110
//TODO: this needs a test
111111
if let Some(ref q) = self.url.query {
112112
uri.push('?');
113-
uri.push_str(q[]);
113+
uri.push_str(&q[]);
114114
}
115115

116-
debug!("writing head: {} {} {}", self.method, uri, self.version);
116+
debug!("writing head: {:?} {:?} {:?}", self.method, uri, self.version);
117117
try!(write!(&mut self.body, "{} {} {}{}",
118118
self.method, uri, self.version, LINE_ENDING));
119119

120120

121121
let stream = match self.method {
122122
Get | Head => {
123-
debug!("headers [\n{}]", self.headers);
123+
debug!("headers [\n{:?}]", self.headers);
124124
try!(write!(&mut self.body, "{}{}", self.headers, LINE_ENDING));
125125
EmptyWriter(self.body.unwrap())
126126
},
@@ -139,7 +139,7 @@ impl Request<Fresh> {
139139
// cant do in match above, thanks borrowck
140140
if chunked {
141141
let encodings = match self.headers.get_mut::<common::TransferEncoding>() {
142-
Some(&common::TransferEncoding(ref mut encodings)) => {
142+
Some(&mut common::TransferEncoding(ref mut encodings)) => {
143143
//TODO: check if chunked is already in encodings. use HashSet?
144144
encodings.push(common::transfer_encoding::Encoding::Chunked);
145145
false
@@ -153,7 +153,7 @@ impl Request<Fresh> {
153153
}
154154
}
155155

156-
debug!("headers [\n{}]", self.headers);
156+
debug!("headers [\n{:?}]", self.headers);
157157
try!(write!(&mut self.body, "{}{}", self.headers, LINE_ENDING));
158158

159159
if chunked {
@@ -218,7 +218,7 @@ mod tests {
218218
let stream = *req.body.end().unwrap()
219219
.into_inner().downcast::<MockStream>().ok().unwrap();
220220
let bytes = stream.write.into_inner();
221-
let s = from_utf8(bytes[]).unwrap();
221+
let s = from_utf8(&bytes[]).unwrap();
222222
assert!(!s.contains("Content-Length:"));
223223
assert!(!s.contains("Transfer-Encoding:"));
224224
}
@@ -232,7 +232,7 @@ mod tests {
232232
let stream = *req.body.end().unwrap()
233233
.into_inner().downcast::<MockStream>().ok().unwrap();
234234
let bytes = stream.write.into_inner();
235-
let s = from_utf8(bytes[]).unwrap();
235+
let s = from_utf8(&bytes[]).unwrap();
236236
assert!(!s.contains("Content-Length:"));
237237
assert!(!s.contains("Transfer-Encoding:"));
238238
}

src/client/response.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ impl Response {
3535
Some(status) => status,
3636
None => return Err(HttpStatusError)
3737
};
38-
debug!("{} {}", version, status);
38+
debug!("{:?} {:?}", version, status);
3939

4040
let headers = try!(header::Headers::from_raw(&mut stream));
41-
debug!("Headers: [\n{}]", headers);
41+
debug!("Headers: [\n{:?}]", headers);
4242

4343
let body = if headers.has::<TransferEncoding>() {
4444
match headers.get::<TransferEncoding>() {
4545
Some(&TransferEncoding(ref codings)) => {
4646
if codings.len() > 1 {
47-
debug!("TODO: #2 handle other codings: {}", codings);
47+
debug!("TODO: #2 handle other codings: {:?}", codings);
4848
};
4949

5050
if codings.contains(&Chunked) {
@@ -88,7 +88,7 @@ impl Response {
8888

8989
impl Reader for Response {
9090
#[inline]
91-
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
91+
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
9292
self.body.read(buf)
9393
}
9494
}

src/header/common/accept.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use mime;
2828
#[derive(Clone, PartialEq, Show)]
2929
pub struct Accept(pub Vec<shared::QualityItem<mime::Mime>>);
3030

31-
deref!(Accept -> Vec<shared::QualityItem<mime::Mime>>);
31+
deref!(Accept => Vec<shared::QualityItem<mime::Mime>>);
3232

3333
impl header::Header for Accept {
3434
fn header_name(_: Option<Accept>) -> &'static str {
@@ -43,7 +43,7 @@ impl header::Header for Accept {
4343

4444
impl header::HeaderFormat for Accept {
4545
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
46-
shared::fmt_comma_delimited(fmt, self[])
46+
shared::fmt_comma_delimited(fmt, &self[])
4747
}
4848
}
4949

src/header/common/accept_encoding.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use header::shared;
1010
#[derive(Clone, PartialEq, Show)]
1111
pub struct AcceptEncoding(pub Vec<shared::QualityItem<shared::Encoding>>);
1212

13-
deref!(AcceptEncoding -> Vec<shared::QualityItem<shared::Encoding>>);
13+
deref!(AcceptEncoding => Vec<shared::QualityItem<shared::Encoding>>);
1414

1515
impl header::Header for AcceptEncoding {
1616
fn header_name(_: Option<AcceptEncoding>) -> &'static str {
@@ -24,7 +24,7 @@ impl header::Header for AcceptEncoding {
2424

2525
impl header::HeaderFormat for AcceptEncoding {
2626
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
27-
shared::fmt_comma_delimited(fmt, self[])
27+
shared::fmt_comma_delimited(fmt, &self[])
2828
}
2929
}
3030

src/header/common/access_control/allow_origin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl header::Header for AccessControlAllowOrigin {
1919

2020
fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowOrigin> {
2121
if raw.len() == 1 {
22-
match str::from_utf8(unsafe { raw[].get_unchecked(0)[] }) {
22+
match str::from_utf8(unsafe { &raw[].get_unchecked(0)[] }) {
2323
Ok(s) => {
2424
if s == "*" {
2525
Some(AccessControlAllowOrigin::AllowStar)

src/header/common/allow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use header::shared::util::{from_comma_delimited, fmt_comma_delimited};
99
#[derive(Clone, PartialEq, Show)]
1010
pub struct Allow(pub Vec<Method>);
1111

12-
deref!(Allow -> Vec<Method>);
12+
deref!(Allow => Vec<Method>);
1313

1414
impl Header for Allow {
1515
fn header_name(_: Option<Allow>) -> &'static str {
@@ -23,7 +23,7 @@ impl Header for Allow {
2323

2424
impl HeaderFormat for Allow {
2525
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
26-
fmt_comma_delimited(fmt, self[])
26+
fmt_comma_delimited(fmt, &self[])
2727
}
2828
}
2929

src/header/common/authorization.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::{self, Show};
1+
use std::fmt;
22
use std::str::{FromStr, from_utf8};
33
use std::ops::{Deref, DerefMut};
44
use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline};
@@ -29,7 +29,7 @@ impl<S: Scheme> Header for Authorization<S> {
2929

3030
fn parse_header(raw: &[Vec<u8>]) -> Option<Authorization<S>> {
3131
if raw.len() == 1 {
32-
match (from_utf8(unsafe { raw[].get_unchecked(0)[] }), Scheme::scheme(None::<S>)) {
32+
match (from_utf8(unsafe { &raw[].get_unchecked(0)[] }), Scheme::scheme(None::<S>)) {
3333
(Ok(header), Some(scheme))
3434
if header.starts_with(scheme) && header.len() > scheme.len() + 1 => {
3535
header[scheme.len() + 1..].parse::<S>().map(|s| Authorization(s))
@@ -70,7 +70,7 @@ impl Scheme for String {
7070
}
7171

7272
fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result {
73-
self.fmt(f)
73+
write!(f, "{}", self)
7474
}
7575
}
7676

@@ -96,14 +96,14 @@ impl Scheme for Basic {
9696
let mut text = self.username.clone();
9797
text.push(':');
9898
if let Some(ref pass) = self.password {
99-
text.push_str(pass[]);
99+
text.push_str(&pass[]);
100100
}
101-
text.as_bytes().to_base64(Config {
101+
write!(f, "{}", text.as_bytes().to_base64(Config {
102102
char_set: Standard,
103103
newline: Newline::CRLF,
104104
pad: true,
105105
line_length: None
106-
}).fmt(f)
106+
}))
107107
}
108108
}
109109

@@ -112,7 +112,7 @@ impl FromStr for Basic {
112112
match s.from_base64() {
113113
Ok(decoded) => match String::from_utf8(decoded) {
114114
Ok(text) => {
115-
let mut parts = text[].split(':');
115+
let mut parts = &mut text[].split(':');
116116
let user = match parts.next() {
117117
Some(part) => part.to_string(),
118118
None => return None
@@ -127,12 +127,12 @@ impl FromStr for Basic {
127127
})
128128
},
129129
Err(e) => {
130-
debug!("Basic::from_utf8 error={}", e);
130+
debug!("Basic::from_utf8 error={:?}", e);
131131
None
132132
}
133133
},
134134
Err(e) => {
135-
debug!("Basic::from_base64 error={}", e);
135+
debug!("Basic::from_base64 error={:?}", e);
136136
None
137137
}
138138
}
@@ -159,7 +159,7 @@ mod tests {
159159
#[test]
160160
fn test_raw_auth_parse() {
161161
let headers = Headers::from_raw(&mut mem("Authorization: foo bar baz\r\n\r\n")).unwrap();
162-
assert_eq!(headers.get::<Authorization<String>>().unwrap().0[], "foo bar baz");
162+
assert_eq!(&headers.get::<Authorization<String>>().unwrap().0[], "foo bar baz");
163163
}
164164

165165
#[test]
@@ -180,7 +180,7 @@ mod tests {
180180
fn test_basic_auth_parse() {
181181
let headers = Headers::from_raw(&mut mem("Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n\r\n")).unwrap();
182182
let auth = headers.get::<Authorization<Basic>>().unwrap();
183-
assert_eq!(auth.0.username[], "Aladdin");
183+
assert_eq!(&auth.0.username[], "Aladdin");
184184
assert_eq!(auth.0.password, Some("open sesame".to_string()));
185185
}
186186

0 commit comments

Comments
 (0)