Merge pull request #269 from hyperium/rustup

fix(rustup): update to newest fmt trait names and slice syntax
This commit is contained in:
Sean McArthur
2015-01-23 15:38:08 -08:00
38 changed files with 90 additions and 114 deletions

View File

@@ -3,7 +3,7 @@ extern crate hyper;
extern crate test; extern crate test;
use std::fmt::{self, Show}; use std::fmt;
use std::io::net::ip::Ipv4Addr; use std::io::net::ip::Ipv4Addr;
use hyper::server::{Request, Response, Server}; use hyper::server::{Request, Response, Server};
use hyper::header::Headers; use hyper::header::Headers;
@@ -44,7 +44,7 @@ impl hyper::header::Header for Foo {
impl hyper::header::HeaderFormat for Foo { impl hyper::header::HeaderFormat for Foo {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
"Bar".fmt(fmt) fmt.write_str("Bar")
} }
} }

View File

@@ -3,7 +3,7 @@ extern crate hyper;
extern crate test; extern crate test;
use std::fmt::{self, Show}; use std::fmt;
use std::io::{IoResult, MemReader}; use std::io::{IoResult, MemReader};
use std::io::net::ip::SocketAddr; use std::io::net::ip::SocketAddr;
@@ -60,7 +60,7 @@ impl hyper::header::Header for Foo {
impl hyper::header::HeaderFormat for Foo { impl hyper::header::HeaderFormat for Foo {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
"Bar".fmt(fmt) fmt.write_str("Bar")
} }
} }

View File

@@ -25,7 +25,7 @@ use mime;
/// qitem(Mime(Text, Html, vec![])), /// qitem(Mime(Text, Html, vec![])),
/// qitem(Mime(Text, Xml, vec![])) ])); /// qitem(Mime(Text, Xml, vec![])) ]));
/// ``` /// ```
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Accept(pub Vec<header::QualityItem<mime::Mime>>); pub struct Accept(pub Vec<header::QualityItem<mime::Mime>>);
deref!(Accept => Vec<header::QualityItem<mime::Mime>>); deref!(Accept => Vec<header::QualityItem<mime::Mime>>);

View File

@@ -4,7 +4,7 @@ use header::{self, Encoding, QualityItem};
/// ///
/// The `Accept-Encoding` header can be used by clients to indicate what /// The `Accept-Encoding` header can be used by clients to indicate what
/// response encodings they accept. /// response encodings they accept.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct AcceptEncoding(pub Vec<QualityItem<Encoding>>); pub struct AcceptEncoding(pub Vec<QualityItem<Encoding>>);
impl_list_header!(AcceptEncoding, impl_list_header!(AcceptEncoding,

View File

@@ -6,7 +6,7 @@ use header::parsing::{from_comma_delimited, fmt_comma_delimited};
/// The `Allow` header. /// The `Allow` header.
/// See also https://tools.ietf.org/html/rfc7231#section-7.4.1 /// See also https://tools.ietf.org/html/rfc7231#section-7.4.1
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Allow(pub Vec<Method>); pub struct Allow(pub Vec<Method>);
deref!(Allow => Vec<Method>); deref!(Allow => Vec<Method>);

View File

@@ -5,7 +5,7 @@ use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline};
use header::{Header, HeaderFormat}; use header::{Header, HeaderFormat};
/// The `Authorization` header field. /// The `Authorization` header field.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Authorization<S: Scheme>(pub S); pub struct Authorization<S: Scheme>(pub S);
impl<S: Scheme> Deref for Authorization<S> { impl<S: Scheme> Deref for Authorization<S> {
@@ -75,7 +75,7 @@ impl Scheme for String {
} }
/// Credential holder for Basic Authentication /// Credential holder for Basic Authentication
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Basic { pub struct Basic {
/// The username as a possibly empty string /// The username as a possibly empty string
pub username: String, pub username: String,
@@ -90,7 +90,7 @@ impl Scheme for Basic {
} }
fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result {
//FIXME: serialize::base64 could use some Show implementation, so //FIXME: serialize::base64 could use some Debug implementation, so
//that we don't have to allocate a new string here just to write it //that we don't have to allocate a new string here just to write it
//to the formatter. //to the formatter.
let mut text = self.username.clone(); let mut text = self.username.clone();

View File

@@ -4,7 +4,7 @@ use header::{Header, HeaderFormat};
use header::parsing::{from_one_comma_delimited, fmt_comma_delimited}; use header::parsing::{from_one_comma_delimited, fmt_comma_delimited};
/// The Cache-Control header. /// The Cache-Control header.
#[derive(PartialEq, Clone, Show)] #[derive(PartialEq, Clone, Debug)]
pub struct CacheControl(pub Vec<CacheDirective>); pub struct CacheControl(pub Vec<CacheDirective>);
deref!(CacheControl => Vec<CacheDirective>); deref!(CacheControl => Vec<CacheDirective>);
@@ -34,7 +34,7 @@ impl HeaderFormat for CacheControl {
} }
/// CacheControl contains a list of these directives. /// CacheControl contains a list of these directives.
#[derive(PartialEq, Clone, Show)] #[derive(PartialEq, Clone, Debug)]
pub enum CacheDirective { pub enum CacheDirective {
/// "no-cache" /// "no-cache"
NoCache, NoCache,
@@ -69,10 +69,10 @@ pub enum CacheDirective {
Extension(String, Option<String>) Extension(String, Option<String>)
} }
impl fmt::String for CacheDirective { impl fmt::Display for CacheDirective {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::CacheDirective::*; use self::CacheDirective::*;
fmt::String::fmt(match *self { fmt::Display::fmt(match *self {
NoCache => "no-cache", NoCache => "no-cache",
NoStore => "no-store", NoStore => "no-store",
NoTransform => "no-transform", NoTransform => "no-transform",

View File

@@ -6,13 +6,13 @@ use header::parsing::{from_comma_delimited, fmt_comma_delimited};
pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader}; pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader};
/// The `Connection` header. /// The `Connection` header.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Connection(pub Vec<ConnectionOption>); pub struct Connection(pub Vec<ConnectionOption>);
deref!(Connection => Vec<ConnectionOption>); deref!(Connection => Vec<ConnectionOption>);
/// Values that can be in the `Connection` header. /// Values that can be in the `Connection` header.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub enum ConnectionOption { pub enum ConnectionOption {
/// The `keep-alive` connection value. /// The `keep-alive` connection value.
KeepAlive, KeepAlive,
@@ -39,7 +39,7 @@ impl FromStr for ConnectionOption {
} }
} }
impl fmt::String for ConnectionOption { impl fmt::Display for ConnectionOption {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", match *self { write!(fmt, "{}", match *self {
KeepAlive => "keep-alive", KeepAlive => "keep-alive",

View File

@@ -6,7 +6,7 @@ use header::parsing::from_one_raw_str;
/// The `Content-Length` header. /// The `Content-Length` header.
/// ///
/// Simply a wrapper around a `usize`. /// Simply a wrapper around a `usize`.
#[derive(Copy, Clone, PartialEq, Show)] #[derive(Copy, Clone, PartialEq, Debug)]
pub struct ContentLength(pub u64); pub struct ContentLength(pub u64);
deref!(ContentLength => u64); deref!(ContentLength => u64);
@@ -23,7 +23,7 @@ impl Header for ContentLength {
impl HeaderFormat for ContentLength { impl HeaderFormat for ContentLength {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(&self.0, fmt) fmt::Display::fmt(&self.0, fmt)
} }
} }

View File

@@ -7,7 +7,7 @@ use mime::Mime;
/// ///
/// Used to describe the MIME type of message body. Can be used with both /// Used to describe the MIME type of message body. Can be used with both
/// requests and responses. /// requests and responses.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct ContentType(pub Mime); pub struct ContentType(pub Mime);
deref!(ContentType => Mime); deref!(ContentType => Mime);
@@ -24,7 +24,7 @@ impl Header for ContentType {
impl HeaderFormat for ContentType { impl HeaderFormat for ContentType {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(&self.0, fmt) fmt::Display::fmt(&self.0, fmt)
} }
} }

View File

@@ -13,7 +13,7 @@ use cookie::CookieJar;
/// ///
/// > When the user agent generates an HTTP request, the user agent MUST NOT /// > When the user agent generates an HTTP request, the user agent MUST NOT
/// > attach more than one Cookie header field. /// > attach more than one Cookie header field.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Cookies(pub Vec<Cookie>); pub struct Cookies(pub Vec<Cookie>);
deref!(Cookies => Vec<Cookie>); deref!(Cookies => Vec<Cookie>);
@@ -53,7 +53,7 @@ impl HeaderFormat for Cookies {
let last = cookies.len() - 1; let last = cookies.len() - 1;
for (i, cookie) in cookies.iter().enumerate() { for (i, cookie) in cookies.iter().enumerate() {
try!(write!(fmt, "{}", cookie.pair())); try!(write!(fmt, "{}", cookie.pair()));
if i < last { if i < last {
try!(fmt.write_str("; ")); try!(fmt.write_str("; "));
} }
} }

View File

@@ -7,7 +7,7 @@ use header::parsing::tm_from_str;
// Egh, replace as soon as something better than time::Tm exists. // Egh, replace as soon as something better than time::Tm exists.
/// The `Date` header field. /// The `Date` header field.
#[derive(Copy, PartialEq, Clone, Show)] #[derive(Copy, PartialEq, Clone, Debug)]
pub struct Date(pub Tm); pub struct Date(pub Tm);
deref!(Date => Tm); deref!(Date => Tm);
@@ -30,7 +30,7 @@ impl HeaderFormat for Date {
0 => tm, 0 => tm,
_ => tm.to_utc(), _ => tm.to_utc(),
}; };
fmt::String::fmt(&tm.rfc822(), fmt) fmt::Display::fmt(&tm.rfc822(), fmt)
} }
} }

View File

@@ -8,7 +8,7 @@ use header::parsing::from_one_raw_str;
/// Preceding the first double quote is an optional weakness indicator, /// Preceding the first double quote is an optional weakness indicator,
/// which always looks like this: W/ /// which always looks like this: W/
/// See also: https://tools.ietf.org/html/rfc7232#section-2.3 /// See also: https://tools.ietf.org/html/rfc7232#section-2.3
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Etag { pub struct Etag {
/// Weakness indicator for the tag /// Weakness indicator for the tag
pub weak: bool, pub weak: bool,

View File

@@ -6,7 +6,7 @@ use header::parsing::from_one_raw_str;
use header::parsing::tm_from_str; use header::parsing::tm_from_str;
/// The `Expires` header field. /// The `Expires` header field.
#[derive(Copy, PartialEq, Clone, Show)] #[derive(Copy, PartialEq, Clone, Debug)]
pub struct Expires(pub Tm); pub struct Expires(pub Tm);
deref!(Expires => Tm); deref!(Expires => Tm);
@@ -29,7 +29,7 @@ impl HeaderFormat for Expires {
0 => tm, 0 => tm,
_ => tm.to_utc(), _ => tm.to_utc(),
}; };
fmt::String::fmt(&tm.rfc822(), fmt) fmt::Display::fmt(&tm.rfc822(), fmt)
} }
} }

View File

@@ -10,7 +10,7 @@ use header::parsing::from_one_raw_str;
/// ///
/// Currently is just a String, but it should probably become a better type, /// Currently is just a String, but it should probably become a better type,
/// like url::Host or something. /// like url::Host or something.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Host { pub struct Host {
/// The hostname, such a example.domain. /// The hostname, such a example.domain.
pub hostname: String, pub hostname: String,
@@ -46,7 +46,7 @@ impl Header for Host {
}; };
let port = match idx { let port = match idx {
Some(idx) => s[].slice_from(idx + 1).parse(), Some(idx) => s[idx + 1..].parse(),
None => None None => None
}; };

View File

@@ -6,7 +6,7 @@ use header::parsing::from_one_raw_str;
use header::parsing::tm_from_str; use header::parsing::tm_from_str;
/// The `If-Modified-Since` header field. /// The `If-Modified-Since` header field.
#[derive(Copy, PartialEq, Clone, Show)] #[derive(Copy, PartialEq, Clone, Debug)]
pub struct IfModifiedSince(pub Tm); pub struct IfModifiedSince(pub Tm);
deref!(IfModifiedSince => Tm); deref!(IfModifiedSince => Tm);
@@ -29,7 +29,7 @@ impl HeaderFormat for IfModifiedSince {
0 => tm, 0 => tm,
_ => tm.to_utc(), _ => tm.to_utc(),
}; };
fmt::String::fmt(&tm.rfc822(), fmt) fmt::Display::fmt(&tm.rfc822(), fmt)
} }
} }

View File

@@ -6,7 +6,7 @@ use header::parsing::from_one_raw_str;
use header::parsing::tm_from_str; use header::parsing::tm_from_str;
/// The `LastModified` header field. /// The `LastModified` header field.
#[derive(Copy, PartialEq, Clone, Show)] #[derive(Copy, PartialEq, Clone, Debug)]
pub struct LastModified(pub Tm); pub struct LastModified(pub Tm);
deref!(LastModified => Tm); deref!(LastModified => Tm);
@@ -29,7 +29,7 @@ impl HeaderFormat for LastModified {
0 => tm, 0 => tm,
_ => tm.to_utc(), _ => tm.to_utc(),
}; };
fmt::String::fmt(&tm.rfc822(), fmt) fmt::Display::fmt(&tm.rfc822(), fmt)
} }
} }

View File

@@ -13,7 +13,7 @@ use header::parsing::from_one_raw_str;
/// ///
/// Currently is just a String, but it should probably become a better type, /// Currently is just a String, but it should probably become a better type,
/// like url::Url or something. /// like url::Url or something.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Location(pub String); pub struct Location(pub String);
deref!(Location => String); deref!(Location => String);

View File

@@ -101,7 +101,7 @@ macro_rules! impl_list_header(
} }
} }
impl ::std::fmt::String for $from { impl ::std::fmt::Display for $from {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
use header::HeaderFormat; use header::HeaderFormat;
self.fmt_header(f) self.fmt_header(f)
@@ -127,11 +127,11 @@ macro_rules! impl_header(
impl header::HeaderFormat for $from { impl header::HeaderFormat for $from {
fn fmt_header(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt_header(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
::std::fmt::String::fmt(&**self, f) ::std::fmt::Display::fmt(&**self, f)
} }
} }
impl ::std::fmt::String for $from { impl ::std::fmt::Display for $from {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
use header::HeaderFormat; use header::HeaderFormat;
self.fmt_header(f) self.fmt_header(f)

View File

@@ -1,5 +1,5 @@
use header::{Header, HeaderFormat}; use header::{Header, HeaderFormat};
use std::fmt::{self, Show}; use std::fmt;
use header::parsing::from_one_raw_str; use header::parsing::from_one_raw_str;
/// The `Referer` header. /// The `Referer` header.
@@ -10,7 +10,7 @@ use header::parsing::from_one_raw_str;
/// See alse [RFC 1945, section 10.13](http://tools.ietf.org/html/rfc1945#section-10.13). /// See alse [RFC 1945, section 10.13](http://tools.ietf.org/html/rfc1945#section-10.13).
/// ///
/// Currently just a string, but maybe better replace it with url::Url or something like it. /// Currently just a string, but maybe better replace it with url::Url or something like it.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Referer(pub String); pub struct Referer(pub String);
deref!(Referer => String); deref!(Referer => String);
@@ -27,8 +27,7 @@ impl Header for Referer {
impl HeaderFormat for Referer { impl HeaderFormat for Referer {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let Referer(ref value) = *self; fmt::Display::fmt(&self.0, fmt)
value.fmt(fmt)
} }
} }

View File

@@ -3,7 +3,7 @@ use header;
/// The `Server` header field. /// The `Server` header field.
/// ///
/// They can contain any value, so it just wraps a `String`. /// They can contain any value, so it just wraps a `String`.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Server(pub String); pub struct Server(pub String);
impl_header!(Server, impl_header!(Server,

View File

@@ -10,7 +10,7 @@ use cookie::CookieJar;
/// Informally, the Set-Cookie response header contains the header name /// Informally, the Set-Cookie response header contains the header name
/// "Set-Cookie" followed by a ":" and a cookie. Each cookie begins with /// "Set-Cookie" followed by a ":" and a cookie. Each cookie begins with
/// a name-value-pair, followed by zero or more attribute-value pairs. /// a name-value-pair, followed by zero or more attribute-value pairs.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct SetCookie(pub Vec<Cookie>); pub struct SetCookie(pub Vec<Cookie>);
deref!(SetCookie => Vec<Cookie>); deref!(SetCookie => Vec<Cookie>);

View File

@@ -16,7 +16,7 @@ use header::parsing::{from_comma_delimited, fmt_comma_delimited};
/// this header should include `chunked` as the last encoding. /// this header should include `chunked` as the last encoding.
/// ///
/// The implementation uses a vector of `Encoding` values. /// The implementation uses a vector of `Encoding` values.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct TransferEncoding(pub Vec<Encoding>); pub struct TransferEncoding(pub Vec<Encoding>);
deref!(TransferEncoding => Vec<Encoding>); deref!(TransferEncoding => Vec<Encoding>);

View File

@@ -6,13 +6,13 @@ use header::parsing::{from_comma_delimited, fmt_comma_delimited};
use self::Protocol::{WebSocket, ProtocolExt}; use self::Protocol::{WebSocket, ProtocolExt};
/// The `Upgrade` header. /// The `Upgrade` header.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct Upgrade(pub Vec<Protocol>); pub struct Upgrade(pub Vec<Protocol>);
deref!(Upgrade => Vec<Protocol>); deref!(Upgrade => Vec<Protocol>);
/// Protocol values that can appear in the Upgrade header. /// Protocol values that can appear in the Upgrade header.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub enum Protocol { pub enum Protocol {
/// The websocket protocol. /// The websocket protocol.
WebSocket, WebSocket,
@@ -29,7 +29,7 @@ impl FromStr for Protocol {
} }
} }
impl fmt::String for Protocol { impl fmt::Display for Protocol {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", match *self { write!(fmt, "{}", match *self {
WebSocket => "websocket", WebSocket => "websocket",

View File

@@ -5,7 +5,7 @@ use header::parsing::from_one_raw_str;
/// The `User-Agent` header field. /// The `User-Agent` header field.
/// ///
/// They can contain any value, so it just wraps a `String`. /// They can contain any value, so it just wraps a `String`.
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub struct UserAgent(pub String); pub struct UserAgent(pub String);
deref!(UserAgent => String); deref!(UserAgent => String);

View File

@@ -6,7 +6,7 @@ use unicase::UniCase;
/// The `Allow` header. /// The `Allow` header.
/// See also https://tools.ietf.org/html/rfc7231#section-7.1.4 /// See also https://tools.ietf.org/html/rfc7231#section-7.1.4
#[derive(Clone, PartialEq, Show)] #[derive(Clone, PartialEq, Debug)]
pub enum Vary { pub enum Vary {
/// This corresponds to '*'. /// This corresponds to '*'.
Any, Any,

View File

@@ -267,7 +267,7 @@ impl Headers {
} }
} }
impl fmt::String for Headers { impl fmt::Display for Headers {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
for header in self.iter() { for header in self.iter() {
try!(write!(fmt, "{}\r\n", header)); try!(write!(fmt, "{}\r\n", header));
@@ -276,7 +276,7 @@ impl fmt::String for Headers {
} }
} }
impl fmt::Show for Headers { impl fmt::Debug for Headers {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
try!(fmt.write_str("Headers {{ ")); try!(fmt.write_str("Headers {{ "));
for header in self.iter() { for header in self.iter() {
@@ -336,15 +336,15 @@ impl<'a> HeaderView<'a> {
} }
} }
impl<'a> fmt::String for HeaderView<'a> { impl<'a> fmt::Display for HeaderView<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}: {}", self.0, *self.1.borrow()) write!(f, "{}: {}", self.0, *self.1.borrow())
} }
} }
impl<'a> fmt::Show for HeaderView<'a> { impl<'a> fmt::Debug for HeaderView<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt) fmt::Display::fmt(self, fmt)
} }
} }
@@ -448,7 +448,7 @@ unsafe fn downcast_mut<H: Header + HeaderFormat>(item: &mut Item) -> &mut H {
item.typed.as_mut().expect("item.typed must be set").downcast_mut_unchecked() item.typed.as_mut().expect("item.typed must be set").downcast_mut_unchecked()
} }
impl fmt::String for Item { impl fmt::Display for Item {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self.typed { match self.typed {
Some(ref h) => h.fmt_header(fmt), Some(ref h) => h.fmt_header(fmt),
@@ -472,13 +472,13 @@ impl fmt::String for Item {
} }
impl fmt::Show for Box<HeaderFormat + Send + Sync> { impl fmt::Debug for Box<HeaderFormat + Send + Sync> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
(**self).fmt_header(fmt) (**self).fmt_header(fmt)
} }
} }
impl fmt::String for Box<HeaderFormat + Send + Sync> { impl fmt::Display for Box<HeaderFormat + Send + Sync> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
(**self).fmt_header(fmt) (**self).fmt_header(fmt)
} }
@@ -491,13 +491,13 @@ impl fmt::String for Box<HeaderFormat + Send + Sync> {
/// outgoing TcpStream. /// outgoing TcpStream.
pub struct HeaderFormatter<'a, H: HeaderFormat>(pub &'a H); pub struct HeaderFormatter<'a, H: HeaderFormat>(pub &'a H);
impl<'a, H: HeaderFormat> fmt::String for HeaderFormatter<'a, H> { impl<'a, H: HeaderFormat> fmt::Display for HeaderFormatter<'a, H> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt_header(f) self.0.fmt_header(f)
} }
} }
impl<'a, H: HeaderFormat> fmt::Show for HeaderFormatter<'a, H> { impl<'a, H: HeaderFormat> fmt::Debug for HeaderFormatter<'a, H> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt_header(f) self.0.fmt_header(f)
} }

View File

@@ -42,7 +42,7 @@ pub fn from_one_comma_delimited<T: str::FromStr>(raw: &[u8]) -> Option<Vec<T>> {
} }
/// Format an array into a comma-delimited string. /// Format an array into a comma-delimited string.
pub fn fmt_comma_delimited<T: fmt::String>(fmt: &mut fmt::Formatter, parts: &[T]) -> fmt::Result { pub fn fmt_comma_delimited<T: fmt::Display>(fmt: &mut fmt::Formatter, parts: &[T]) -> fmt::Result {
let last = parts.len() - 1; let last = parts.len() - 1;
for (i, part) in parts.iter().enumerate() { for (i, part) in parts.iter().enumerate() {
try!(write!(fmt, "{}", part)); try!(write!(fmt, "{}", part));

View File

@@ -7,7 +7,7 @@ pub use self::Encoding::{Chunked, Gzip, Deflate, Compress, Identity, EncodingExt
/// A value to represent an encoding used in `Transfer-Encoding` /// A value to represent an encoding used in `Transfer-Encoding`
/// or `Accept-Encoding` header. /// or `Accept-Encoding` header.
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq, Debug)]
pub enum Encoding { pub enum Encoding {
/// The `chunked` encoding. /// The `chunked` encoding.
Chunked, Chunked,
@@ -23,9 +23,9 @@ pub enum Encoding {
EncodingExt(String) EncodingExt(String)
} }
impl fmt::String for Encoding { impl fmt::Display for Encoding {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", match *self { fmt.write_str(match *self {
Chunked => "chunked", Chunked => "chunked",
Gzip => "gzip", Gzip => "gzip",
Deflate => "deflate", Deflate => "deflate",
@@ -33,13 +33,7 @@ impl fmt::String for Encoding {
Identity => "identity", Identity => "identity",
EncodingExt(ref s) => s.as_slice() EncodingExt(ref s) => s.as_slice()
}) })
} }
}
impl fmt::Show for Encoding {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt)
}
} }
impl str::FromStr for Encoding { impl str::FromStr for Encoding {

View File

@@ -9,7 +9,7 @@ use std::str;
/// Represents an item with a quality value as defined in /// Represents an item with a quality value as defined in
/// [RFC7231](https://tools.ietf.org/html/rfc7231#section-5.3.1). /// [RFC7231](https://tools.ietf.org/html/rfc7231#section-5.3.1).
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq, Debug)]
pub struct QualityItem<T> { pub struct QualityItem<T> {
/// The actual contents of the field. /// The actual contents of the field.
pub item: T, pub item: T,
@@ -26,13 +26,7 @@ impl<T> QualityItem<T> {
} }
} }
impl<T: fmt::String> fmt::String for QualityItem<T> { impl<T: fmt::Display> fmt::Display for QualityItem<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}; q={}", self.item, format!("{:.3}", self.quality).trim_right_matches(['0', '.'].as_slice()))
}
}
impl<T: fmt::String> fmt::Show for QualityItem<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}; q={}", self.item, format!("{:.3}", self.quality).trim_right_matches(['0', '.'].as_slice())) write!(f, "{}; q={}", self.item, format!("{:.3}", self.quality).trim_right_matches(['0', '.'].as_slice()))
} }
@@ -46,9 +40,9 @@ impl<T: str::FromStr> str::FromStr for QualityItem<T> {
let parts: Vec<&str> = s.rsplitn(1, ';').map(|x| x.trim()).collect(); let parts: Vec<&str> = s.rsplitn(1, ';').map(|x| x.trim()).collect();
if parts.len() == 2 { if parts.len() == 2 {
let start = parts[0].slice(0, 2); let start = &parts[0][0..2];
if start == "q=" || start == "Q=" { if start == "q=" || start == "Q=" {
let q_part = parts[0].slice(2, parts[0].len()); let q_part = &parts[0][2..parts[0].len()];
if q_part.len() > 5 { if q_part.len() > 5 {
return None; return None;
} }

View File

@@ -2,7 +2,6 @@
use std::borrow::Cow::{Borrowed, Owned}; use std::borrow::Cow::{Borrowed, Owned};
use std::borrow::IntoCow; use std::borrow::IntoCow;
use std::cmp::min; use std::cmp::min;
use std::fmt;
use std::io::{self, Reader, IoResult, BufWriter}; use std::io::{self, Reader, IoResult, BufWriter};
use std::num::from_u16; use std::num::from_u16;
use std::str::{self, FromStr}; use std::str::{self, FromStr};
@@ -103,7 +102,7 @@ impl<R: Reader> Reader for HttpReader<R> {
} }
let to_read = min(rem as usize, buf.len()); let to_read = min(rem as usize, buf.len());
let count = try!(body.read(buf.slice_to_mut(to_read))) as u64; let count = try!(body.read(&mut buf[..to_read])) as u64;
rem -= count; rem -= count;
*opt_remaining = if rem > 0 { *opt_remaining = if rem > 0 {
@@ -306,23 +305,6 @@ pub const LF: u8 = b'\n';
pub const STAR: u8 = b'*'; pub const STAR: u8 = b'*';
pub const LINE_ENDING: &'static str = "\r\n"; pub const LINE_ENDING: &'static str = "\r\n";
/// A `Show`able struct to easily write line endings to a formatter.
pub struct LineEnding;
impl Copy for LineEnding {}
impl fmt::String for LineEnding {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_str(LINE_ENDING)
}
}
impl fmt::Show for LineEnding {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.to_string().fmt(fmt)
}
}
/// Determines if byte is a token char. /// Determines if byte is a token char.
/// ///
/// > ```notrust /// > ```notrust

View File

@@ -145,6 +145,7 @@ pub use status::StatusCode::{Ok, BadRequest, NotFound};
pub use server::Server; pub use server::Server;
use std::error::{Error, FromError}; use std::error::{Error, FromError};
use std::fmt;
use std::io::IoError; use std::io::IoError;
use self::HttpError::{HttpMethodError, HttpUriError, HttpVersionError, use self::HttpError::{HttpMethodError, HttpUriError, HttpVersionError,
@@ -189,7 +190,7 @@ mod mimewrapper {
pub type HttpResult<T> = Result<T, HttpError>; pub type HttpResult<T> = Result<T, HttpError>;
/// A set of errors that can occur parsing HTTP streams. /// A set of errors that can occur parsing HTTP streams.
#[derive(Show, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub enum HttpError { pub enum HttpError {
/// An invalid `Method`, such as `GE,T`. /// An invalid `Method`, such as `GE,T`.
HttpMethodError, HttpMethodError,
@@ -205,6 +206,12 @@ pub enum HttpError {
HttpIoError(IoError), HttpIoError(IoError),
} }
impl fmt::Display for HttpError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.description())
}
}
impl Error for HttpError { impl Error for HttpError {
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {

View File

@@ -13,7 +13,7 @@ use self::Method::{Options, Get, Post, Put, Delete, Head, Trace, Connect, Patch,
/// ///
/// It may make sense to grow this to include all variants currently /// It may make sense to grow this to include all variants currently
/// registered with IANA, if they are at all common to use. /// registered with IANA, if they are at all common to use.
#[derive(Clone, PartialEq, Eq, Hash, Show)] #[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub enum Method { pub enum Method {
/// OPTIONS /// OPTIONS
Options, Options,
@@ -88,9 +88,9 @@ impl FromStr for Method {
} }
} }
impl fmt::String for Method { impl fmt::Display for Method {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self { fmt.write_str(match *self {
Options => "OPTIONS", Options => "OPTIONS",
Get => "GET", Get => "GET",
Post => "POST", Post => "POST",
@@ -101,7 +101,7 @@ impl fmt::String for Method {
Connect => "CONNECT", Connect => "CONNECT",
Patch => "PATCH", Patch => "PATCH",
Extension(ref s) => s.as_slice() Extension(ref s) => s.as_slice()
}.fmt(fmt) })
} }
} }

View File

@@ -25,7 +25,7 @@ impl PartialEq for MockStream {
} }
} }
impl fmt::Show for MockStream { impl fmt::Debug for MockStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "MockStream {{ read: {:?}, write: {:?} }}", write!(f, "MockStream {{ read: {:?}, write: {:?} }}",
self.read.get_ref(), self.write.get_ref()) self.read.get_ref(), self.write.get_ref())

View File

@@ -94,7 +94,7 @@ pub trait NetworkConnector {
fn connect(&mut self, host: &str, port: Port, scheme: &str) -> IoResult<Self::Stream>; fn connect(&mut self, host: &str, port: Port, scheme: &str) -> IoResult<Self::Stream>;
} }
impl fmt::Show for Box<NetworkStream + Send> { impl fmt::Debug for Box<NetworkStream + Send> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.pad("Box<NetworkStream>") fmt.pad("Box<NetworkStream>")
} }

View File

@@ -26,7 +26,7 @@ use std::cmp::Ordering::{self, Less, Equal, Greater};
/// # use hyper::status::StatusCode::{Code123, Continue}; /// # use hyper::status::StatusCode::{Code123, Continue};
/// assert_eq!(Code123.class().default_code(), Continue); /// assert_eq!(Code123.class().default_code(), Continue);
/// ``` /// ```
#[derive(Show)] #[derive(Debug)]
pub enum StatusCode { pub enum StatusCode {
/// 100 Continue /// 100 Continue
Continue = 100, Continue = 100,
@@ -1589,7 +1589,7 @@ impl Copy for StatusCode {}
/// ``` /// ```
/// ///
/// If you wish to just include the number, cast to a u16 instead. /// If you wish to just include the number, cast to a u16 instead.
impl fmt::String for StatusCode { impl fmt::Display for StatusCode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {}", *self as u16, write!(f, "{} {}", *self as u16,
self.canonical_reason().unwrap_or("<unknown status code>")) self.canonical_reason().unwrap_or("<unknown status code>"))

View File

@@ -16,7 +16,7 @@ use url::Url;
/// > / authority-form /// > / authority-form
/// > / asterisk-form /// > / asterisk-form
/// > ``` /// > ```
#[derive(Show, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub enum RequestUri { pub enum RequestUri {
/// The most common request target, an absolute path and optional query. /// The most common request target, an absolute path and optional query.
/// ///

View File

@@ -7,7 +7,7 @@ use std::fmt;
use self::HttpVersion::{Http09, Http10, Http11, Http20}; use self::HttpVersion::{Http09, Http10, Http11, Http20};
/// Represents a version of the HTTP spec. /// Represents a version of the HTTP spec.
#[derive(PartialEq, PartialOrd, Copy, Show)] #[derive(PartialEq, PartialOrd, Copy, Debug)]
pub enum HttpVersion { pub enum HttpVersion {
/// `HTTP/0.9` /// `HTTP/0.9`
Http09, Http09,
@@ -19,14 +19,14 @@ pub enum HttpVersion {
Http20 Http20
} }
impl fmt::String for HttpVersion { impl fmt::Display for HttpVersion {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self { fmt.write_str(match *self {
Http09 => "HTTP/0.9", Http09 => "HTTP/0.9",
Http10 => "HTTP/1.0", Http10 => "HTTP/1.0",
Http11 => "HTTP/1.1", Http11 => "HTTP/1.1",
Http20 => "HTTP/2.0", Http20 => "HTTP/2.0",
}.fmt(fmt) })
} }
} }