Update for latest rust

Tracks rust nightly.

7 tests fail -- still finding source
This commit is contained in:
cyderize
2015-01-10 18:37:10 +11:00
parent 241ebc1270
commit 122e94c8a6
42 changed files with 291 additions and 189 deletions

View File

@@ -28,7 +28,7 @@ use mime;
#[derive(Clone, PartialEq, Show)]
pub struct Accept(pub Vec<shared::QualityItem<mime::Mime>>);
deref!(Accept -> Vec<shared::QualityItem<mime::Mime>>);
deref!(Accept => Vec<shared::QualityItem<mime::Mime>>);
impl header::Header for Accept {
fn header_name(_: Option<Accept>) -> &'static str {
@@ -43,7 +43,7 @@ impl header::Header for Accept {
impl header::HeaderFormat for Accept {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
shared::fmt_comma_delimited(fmt, self[])
shared::fmt_comma_delimited(fmt, &self[])
}
}

View File

@@ -10,7 +10,7 @@ use header::shared;
#[derive(Clone, PartialEq, Show)]
pub struct AcceptEncoding(pub Vec<shared::QualityItem<shared::Encoding>>);
deref!(AcceptEncoding -> Vec<shared::QualityItem<shared::Encoding>>);
deref!(AcceptEncoding => Vec<shared::QualityItem<shared::Encoding>>);
impl header::Header for AcceptEncoding {
fn header_name(_: Option<AcceptEncoding>) -> &'static str {
@@ -24,7 +24,7 @@ impl header::Header for AcceptEncoding {
impl header::HeaderFormat for AcceptEncoding {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
shared::fmt_comma_delimited(fmt, self[])
shared::fmt_comma_delimited(fmt, &self[])
}
}

View File

@@ -19,7 +19,7 @@ impl header::Header for AccessControlAllowOrigin {
fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowOrigin> {
if raw.len() == 1 {
match str::from_utf8(unsafe { raw[].get_unchecked(0)[] }) {
match str::from_utf8(unsafe { &raw[].get_unchecked(0)[] }) {
Ok(s) => {
if s == "*" {
Some(AccessControlAllowOrigin::AllowStar)

View File

@@ -9,7 +9,7 @@ use header::shared::util::{from_comma_delimited, fmt_comma_delimited};
#[derive(Clone, PartialEq, Show)]
pub struct Allow(pub Vec<Method>);
deref!(Allow -> Vec<Method>);
deref!(Allow => Vec<Method>);
impl Header for Allow {
fn header_name(_: Option<Allow>) -> &'static str {
@@ -23,7 +23,7 @@ impl Header for Allow {
impl HeaderFormat for Allow {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt_comma_delimited(fmt, self[])
fmt_comma_delimited(fmt, &self[])
}
}

View File

@@ -29,7 +29,7 @@ impl<S: Scheme> Header for Authorization<S> {
fn parse_header(raw: &[Vec<u8>]) -> Option<Authorization<S>> {
if raw.len() == 1 {
match (from_utf8(unsafe { raw[].get_unchecked(0)[] }), Scheme::scheme(None::<S>)) {
match (from_utf8(unsafe { &raw[].get_unchecked(0)[] }), Scheme::scheme(None::<S>)) {
(Ok(header), Some(scheme))
if header.starts_with(scheme) && header.len() > scheme.len() + 1 => {
header[scheme.len() + 1..].parse::<S>().map(|s| Authorization(s))
@@ -96,7 +96,7 @@ impl Scheme for Basic {
let mut text = self.username.clone();
text.push(':');
if let Some(ref pass) = self.password {
text.push_str(pass[]);
text.push_str(&pass[]);
}
text.as_bytes().to_base64(Config {
char_set: Standard,
@@ -112,7 +112,7 @@ impl FromStr for Basic {
match s.from_base64() {
Ok(decoded) => match String::from_utf8(decoded) {
Ok(text) => {
let mut parts = text[].split(':');
let mut parts = &mut text[].split(':');
let user = match parts.next() {
Some(part) => part.to_string(),
None => return None
@@ -127,12 +127,12 @@ impl FromStr for Basic {
})
},
Err(e) => {
debug!("Basic::from_utf8 error={}", e);
debug!("Basic::from_utf8 error={:?}", e);
None
}
},
Err(e) => {
debug!("Basic::from_base64 error={}", e);
debug!("Basic::from_base64 error={:?}", e);
None
}
}
@@ -159,7 +159,7 @@ mod tests {
#[test]
fn test_raw_auth_parse() {
let headers = Headers::from_raw(&mut mem("Authorization: foo bar baz\r\n\r\n")).unwrap();
assert_eq!(headers.get::<Authorization<String>>().unwrap().0[], "foo bar baz");
assert_eq!(&headers.get::<Authorization<String>>().unwrap().0[], "foo bar baz");
}
#[test]
@@ -180,7 +180,7 @@ mod tests {
fn test_basic_auth_parse() {
let headers = Headers::from_raw(&mut mem("Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n\r\n")).unwrap();
let auth = headers.get::<Authorization<Basic>>().unwrap();
assert_eq!(auth.0.username[], "Aladdin");
assert_eq!(&auth.0.username[], "Aladdin");
assert_eq!(auth.0.password, Some("open sesame".to_string()));
}

View File

@@ -7,7 +7,7 @@ use header::shared::util::{from_one_comma_delimited, fmt_comma_delimited};
#[derive(PartialEq, Clone, Show)]
pub struct CacheControl(pub Vec<CacheDirective>);
deref!(CacheControl -> Vec<CacheDirective>);
deref!(CacheControl => Vec<CacheDirective>);
impl Header for CacheControl {
fn header_name(_: Option<CacheControl>) -> &'static str {
@@ -16,7 +16,7 @@ impl Header for CacheControl {
fn parse_header(raw: &[Vec<u8>]) -> Option<CacheControl> {
let directives = raw.iter()
.filter_map(|line| from_one_comma_delimited(line[]))
.filter_map(|line| from_one_comma_delimited(&line[]))
.collect::<Vec<Vec<CacheDirective>>>()
.concat();
if directives.len() > 0 {
@@ -29,7 +29,7 @@ impl Header for CacheControl {
impl HeaderFormat for CacheControl {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt_comma_delimited(fmt, self[])
fmt_comma_delimited(fmt, &self[])
}
}
@@ -47,11 +47,11 @@ pub enum CacheDirective {
// request directives
/// "max-age=delta"
MaxAge(uint),
MaxAge(usize),
/// "max-stale=delta"
MaxStale(uint),
MaxStale(usize),
/// "min-fresh=delta"
MinFresh(uint),
MinFresh(usize),
// response directives
/// "must-revalidate"
@@ -63,13 +63,13 @@ pub enum CacheDirective {
/// "proxy-revalidate"
ProxyRevalidate,
/// "s-maxage=delta"
SMaxAge(uint),
SMaxAge(usize),
/// Extension directives. Optionally include an argument.
Extension(String, Option<String>)
}
impl fmt::Show for CacheDirective {
impl fmt::String for CacheDirective {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::CacheDirective::*;
match *self {
@@ -88,13 +88,18 @@ impl fmt::Show for CacheDirective {
ProxyRevalidate => "proxy-revalidate",
SMaxAge(secs) => return write!(f, "s-maxage={}", secs),
Extension(ref name, None) => name[],
Extension(ref name, None) => &name[],
Extension(ref name, Some(ref arg)) => return write!(f, "{}={}", name, arg),
}.fmt(f)
}
}
impl fmt::Show for CacheDirective {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt)
}
}
impl FromStr for CacheDirective {
fn from_str(s: &str) -> Option<CacheDirective> {
use self::CacheDirective::*;
@@ -109,7 +114,7 @@ impl FromStr for CacheDirective {
"proxy-revalidate" => Some(ProxyRevalidate),
"" => None,
_ => match s.find('=') {
Some(idx) if idx+1 < s.len() => match (s[..idx], s[idx+1..].trim_matches('"')) {
Some(idx) if idx+1 < s.len() => match (&s[..idx], &s[idx+1..].trim_matches('"')) {
("max-age" , secs) => secs.parse().map(MaxAge),
("max-stale", secs) => secs.parse().map(MaxStale),
("min-fresh", secs) => secs.parse().map(MinFresh),

View File

@@ -9,7 +9,7 @@ pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader};
#[derive(Clone, PartialEq, Show)]
pub struct Connection(pub Vec<ConnectionOption>);
deref!(Connection -> Vec<ConnectionOption>);
deref!(Connection => Vec<ConnectionOption>);
/// Values that can be in the `Connection` header.
#[derive(Clone, PartialEq)]
@@ -39,16 +39,22 @@ impl FromStr for ConnectionOption {
}
}
impl fmt::Show for ConnectionOption {
impl fmt::String for ConnectionOption {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
write!(fmt, "{}", match *self {
KeepAlive => "keep-alive",
Close => "close",
ConnectionHeader(ref s) => s.as_slice()
}.fmt(fmt)
})
}
}
impl fmt::Show for ConnectionOption {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt)
}
}
impl Header for Connection {
fn header_name(_: Option<Connection>) -> &'static str {
"Connection"
@@ -62,7 +68,7 @@ impl Header for Connection {
impl HeaderFormat for Connection {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let Connection(ref parts) = *self;
fmt_comma_delimited(fmt, parts[])
fmt_comma_delimited(fmt, &parts[])
}
}

View File

@@ -5,11 +5,11 @@ use header::shared::util::from_one_raw_str;
/// The `Content-Length` header.
///
/// Simply a wrapper around a `uint`.
/// Simply a wrapper around a `usize`.
#[derive(Copy, Clone, PartialEq, Show)]
pub struct ContentLength(pub uint);
pub struct ContentLength(pub usize);
deref!(ContentLength -> uint);
deref!(ContentLength => usize);
impl Header for ContentLength {
fn header_name(_: Option<ContentLength>) -> &'static str {
@@ -32,7 +32,7 @@ impl ContentLength {
/// Returns the wrapped length.
#[deprecated = "use Deref instead"]
#[inline]
pub fn len(&self) -> uint {
pub fn len(&self) -> usize {
**self
}
}

View File

@@ -10,7 +10,7 @@ use mime::Mime;
#[derive(Clone, PartialEq, Show)]
pub struct ContentType(pub Mime);
deref!(ContentType -> Mime);
deref!(ContentType => Mime);
impl Header for ContentType {
fn header_name(_: Option<ContentType>) -> &'static str {

View File

@@ -20,7 +20,7 @@ pub struct Cookies(pub Vec<Cookie>);
unsafe impl Send for Cookies {}
unsafe impl Sync for Cookies {}
deref!(Cookies -> Vec<Cookie>);
deref!(Cookies => Vec<Cookie>);
impl Header for Cookies {
fn header_name(_: Option<Cookies>) -> &'static str {
@@ -30,7 +30,7 @@ impl Header for Cookies {
fn parse_header(raw: &[Vec<u8>]) -> Option<Cookies> {
let mut cookies = Vec::with_capacity(raw.len());
for cookies_raw in raw.iter() {
match from_utf8(cookies_raw[]) {
match from_utf8(&cookies_raw[]) {
Ok(cookies_str) => {
for cookie_str in cookies_str.split(';') {
match cookie_str.trim().parse() {
@@ -56,8 +56,8 @@ impl HeaderFormat for Cookies {
let cookies = &self.0;
let last = cookies.len() - 1;
for (i, cookie) in cookies.iter().enumerate() {
try!(cookie.pair().fmt(fmt));
if i < last {
try!(write!(fmt, "{}", cookie.pair()));
if i < last {
try!("; ".fmt(fmt));
}
}
@@ -86,7 +86,7 @@ impl Cookies {
#[test]
fn test_parse() {
let h = Header::parse_header([b"foo=bar; baz=quux".to_vec()][]);
let h = Header::parse_header(&[b"foo=bar; baz=quux".to_vec()][]);
let c1 = Cookie::new("foo".to_string(), "bar".to_string());
let c2 = Cookie::new("baz".to_string(), "quux".to_string());
assert_eq!(h, Some(Cookies(vec![c1, c2])));
@@ -103,7 +103,7 @@ fn test_fmt() {
let mut headers = Headers::new();
headers.set(cookies);
assert_eq!(headers.to_string()[], "Cookie: foo=bar; baz=quux\r\n");
assert_eq!(&headers.to_string()[], "Cookie: foo=bar; baz=quux\r\n");
}
#[test]

View File

@@ -10,7 +10,7 @@ use header::shared::time::tm_from_str;
#[derive(Copy, PartialEq, Clone)]
pub struct Date(pub Tm);
deref!(Date -> Tm);
deref!(Date => Tm);
impl Header for Date {
fn header_name(_: Option<Date>) -> &'static str {

View File

@@ -38,8 +38,8 @@ impl Header for Etag {
from_one_raw_str(raw).and_then(|s: String| {
let length: uint = s.len();
let slice = s[];
let length: usize = s.len();
let slice = &s[];
// Early exits:
// 1. The string is empty, or,

View File

@@ -9,7 +9,7 @@ use header::shared::time::tm_from_str;
#[derive(Copy, PartialEq, Clone)]
pub struct Expires(pub Tm);
deref!(Expires -> Tm);
deref!(Expires => Tm);
impl Header for Expires {
fn header_name(_: Option<Expires>) -> &'static str {

View File

@@ -28,7 +28,7 @@ impl Header for Host {
// FIXME: use rust-url to parse this
// https://github.com/servo/rust-url/issues/42
let idx = {
let slice = s[];
let slice = &s[];
if slice.char_at(1) == '[' {
match slice.rfind(']') {
Some(idx) => {

View File

@@ -9,7 +9,7 @@ use header::shared::time::tm_from_str;
#[derive(Copy, PartialEq, Clone)]
pub struct IfModifiedSince(pub Tm);
deref!(IfModifiedSince -> Tm);
deref!(IfModifiedSince => Tm);
impl Header for IfModifiedSince {
fn header_name(_: Option<IfModifiedSince>) -> &'static str {

View File

@@ -9,7 +9,7 @@ use header::shared::time::tm_from_str;
#[derive(Copy, PartialEq, Clone)]
pub struct LastModified(pub Tm);
deref!(LastModified -> Tm);
deref!(LastModified => Tm);
impl Header for LastModified {
fn header_name(_: Option<LastModified>) -> &'static str {

View File

@@ -16,7 +16,7 @@ use header::shared::util::from_one_raw_str;
#[derive(Clone, PartialEq, Show)]
pub struct Location(pub String);
deref!(Location -> String);
deref!(Location => String);
impl Header for Location {
fn header_name(_: Option<Location>) -> &'static str {

View File

@@ -42,13 +42,13 @@ macro_rules! bench_header(
fn bench_parse(b: &mut Bencher) {
let val = $value;
b.iter(|| {
let _: $ty = Header::parse_header(val[]).unwrap();
let _: $ty = Header::parse_header(&val[]).unwrap();
});
}
#[bench]
fn bench_format(b: &mut Bencher) {
let val: $ty = Header::parse_header($value[]).unwrap();
let val: $ty = Header::parse_header(&$value[]).unwrap();
let fmt = HeaderFormatter(&val);
b.iter(|| {
format!("{}", fmt);
@@ -59,7 +59,7 @@ macro_rules! bench_header(
);
macro_rules! deref(
($from:ty -> $to:ty) => {
($from:ty => $to:ty) => {
impl ::std::ops::Deref for $from {
type Target = $to;

View File

@@ -8,7 +8,7 @@ use header::shared::util::from_one_raw_str;
#[derive(Clone, PartialEq, Show)]
pub struct Server(pub String);
deref!(Server -> String);
deref!(Server => String);
impl Header for Server {
fn header_name(_: Option<Server>) -> &'static str {

View File

@@ -17,7 +17,7 @@ pub struct SetCookie(pub Vec<Cookie>);
unsafe impl Send for SetCookie {}
unsafe impl Sync for SetCookie {}
deref!(SetCookie -> Vec<Cookie>);
deref!(SetCookie => Vec<Cookie>);
impl Header for SetCookie {
fn header_name(_: Option<SetCookie>) -> &'static str {
@@ -27,7 +27,7 @@ impl Header for SetCookie {
fn parse_header(raw: &[Vec<u8>]) -> Option<SetCookie> {
let mut set_cookies = Vec::with_capacity(raw.len());
for set_cookies_raw in raw.iter() {
match from_utf8(set_cookies_raw[]) {
match from_utf8(&set_cookies_raw[]) {
Ok(s) if !s.is_empty() => {
match s.parse() {
Some(cookie) => set_cookies.push(cookie),
@@ -80,7 +80,7 @@ impl SetCookie {
#[test]
fn test_parse() {
let h = Header::parse_header([b"foo=bar; HttpOnly".to_vec()][]);
let h = Header::parse_header(&[b"foo=bar; HttpOnly".to_vec()][]);
let mut c1 = Cookie::new("foo".to_string(), "bar".to_string());
c1.httponly = true;
@@ -98,7 +98,7 @@ fn test_fmt() {
let mut headers = Headers::new();
headers.set(cookies);
assert_eq!(headers.to_string()[], "Set-Cookie: foo=bar; HttpOnly; Path=/p\r\nSet-Cookie: baz=quux; Path=/\r\n");
assert_eq!(&headers.to_string()[], "Set-Cookie: foo=bar; HttpOnly; Path=/p\r\nSet-Cookie: baz=quux; Path=/\r\n");
}
#[test]

View File

@@ -21,7 +21,7 @@ use self::Encoding::{Chunked, Gzip, Deflate, Compress, EncodingExt};
#[derive(Clone, PartialEq, Show)]
pub struct TransferEncoding(pub Vec<Encoding>);
deref!(TransferEncoding -> Vec<Encoding>);
deref!(TransferEncoding => Vec<Encoding>);
/// A value to be used with the `Transfer-Encoding` header.
///
@@ -47,18 +47,24 @@ pub enum Encoding {
EncodingExt(String)
}
impl fmt::Show for Encoding {
impl fmt::String for Encoding {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
write!(fmt, "{}", match *self {
Chunked => "chunked",
Gzip => "gzip",
Deflate => "deflate",
Compress => "compress",
EncodingExt(ref s) => s.as_slice()
}.fmt(fmt)
})
}
}
impl fmt::Show for Encoding {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt)
}
}
impl FromStr for Encoding {
fn from_str(s: &str) -> Option<Encoding> {
match s {
@@ -83,7 +89,7 @@ impl Header for TransferEncoding {
impl HeaderFormat for TransferEncoding {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt_comma_delimited(fmt, self[])
fmt_comma_delimited(fmt, &self[])
}
}

View File

@@ -9,7 +9,7 @@ use self::Protocol::{WebSocket, ProtocolExt};
#[derive(Clone, PartialEq, Show)]
pub struct Upgrade(pub Vec<Protocol>);
deref!(Upgrade -> Vec<Protocol>);
deref!(Upgrade => Vec<Protocol>);
/// Protocol values that can appear in the Upgrade header.
#[derive(Clone, PartialEq)]
@@ -29,12 +29,18 @@ impl FromStr for Protocol {
}
}
impl fmt::Show for Protocol {
impl fmt::String for Protocol {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
write!(fmt, "{}", match *self {
WebSocket => "websocket",
ProtocolExt(ref s) => s.as_slice()
}.fmt(fmt)
})
}
}
impl fmt::Show for Protocol {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt)
}
}
@@ -51,7 +57,7 @@ impl Header for Upgrade {
impl HeaderFormat for Upgrade {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let Upgrade(ref parts) = *self;
fmt_comma_delimited(fmt, parts[])
fmt_comma_delimited(fmt, &parts[])
}
}

View File

@@ -8,7 +8,7 @@ use header::shared::util::from_one_raw_str;
#[derive(Clone, PartialEq, Show)]
pub struct UserAgent(pub String);
deref!(UserAgent -> String);
deref!(UserAgent => String);
impl Header for UserAgent {
fn header_name(_: Option<UserAgent>) -> &'static str {

View File

@@ -20,7 +20,7 @@ impl Header for Vary {
fn parse_header(raw: &[Vec<u8>]) -> Option<Vary> {
from_one_raw_str(raw).and_then(|s: String| {
let slice = s[];
let slice = &s[];
match slice {
"" => None,
"*" => Some(Vary::Any),
@@ -34,7 +34,7 @@ impl HeaderFormat for Vary {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
Vary::Any => { write!(fmt, "*") }
Vary::Headers(ref fields) => { fmt_comma_delimited(fmt, fields[]) }
Vary::Headers(ref fields) => { fmt_comma_delimited(fmt, &fields[]) }
}
}
}