Skip to content

Commit

Permalink
fix(rustup): Add PhantomData markers to phantom type users
Browse files Browse the repository at this point in the history
  • Loading branch information
renato-zannon authored and seanmonstar committed Feb 21, 2015
1 parent 039e984 commit 1904c45
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/client/request.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Client Requests
use std::old_io::{BufferedWriter, IoResult};
use std::marker::PhantomData;

use url::Url;

Expand All @@ -25,6 +26,8 @@ pub struct Request<W> {
body: HttpWriter<BufferedWriter<Box<NetworkStream + Send>>>,
headers: Headers,
method: method::Method,

_marker: PhantomData<W>,
}

impl<W> Request<W> {
Expand Down Expand Up @@ -66,7 +69,8 @@ impl Request<Fresh> {
headers: headers,
url: url,
version: version::HttpVersion::Http11,
body: stream
body: stream,
_marker: PhantomData,
})
}

Expand Down Expand Up @@ -136,7 +140,8 @@ impl Request<Fresh> {
headers: self.headers,
url: self.url,
version: self.version,
body: stream
body: stream,
_marker: PhantomData,
})
}

Expand Down
8 changes: 7 additions & 1 deletion src/client/response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Client Responses
use std::num::FromPrimitive;
use std::old_io::{BufferedReader, IoResult};
use std::marker::PhantomData;

use header;
use header::{ContentLength, TransferEncoding};
Expand All @@ -23,6 +24,8 @@ pub struct Response<S = HttpStream> {
pub version: version::HttpVersion,
status_raw: RawStatus,
body: HttpReader<BufferedReader<Box<NetworkStream + Send>>>,

_marker: PhantomData<S>,
}

impl Response {
Expand Down Expand Up @@ -72,6 +75,7 @@ impl Response {
headers: headers,
body: body,
status_raw: raw_status,
_marker: PhantomData,
})
}

Expand All @@ -98,6 +102,7 @@ mod tests {
use std::borrow::Cow::Borrowed;
use std::boxed::BoxAny;
use std::old_io::BufferedReader;
use std::marker::PhantomData;

use header::Headers;
use header::TransferEncoding;
Expand All @@ -119,7 +124,8 @@ mod tests {
headers: Headers::new(),
version: version::HttpVersion::Http11,
body: EofReader(BufferedReader::new(box MockStream::new() as Box<NetworkStream + Send>)),
status_raw: RawStatus(200, Borrowed("OK"))
status_raw: RawStatus(200, Borrowed("OK")),
_marker: PhantomData,
};

let b = res.into_inner().downcast::<MockStream>().ok().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<S: Scheme> DerefMut for Authorization<S> {
}
}

impl<S: Scheme + 'static> Header for Authorization<S> {
impl<S: Scheme + 'static> Header for Authorization<S> where <S as FromStr>::Err: 'static {
fn header_name() -> &'static str {
"Authorization"
}
Expand All @@ -43,7 +43,7 @@ impl<S: Scheme + 'static> Header for Authorization<S> {
}
}

impl<S: Scheme + 'static> HeaderFormat for Authorization<S> {
impl<S: Scheme + 'static> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match Scheme::scheme(None::<S>) {
Some(scheme) => try!(write!(fmt, "{} ", scheme)),
Expand Down
14 changes: 10 additions & 4 deletions src/server/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! These are responses sent by a `hyper::Server` to clients, after
//! receiving a request.
use std::old_io::IoResult;
use std::marker::PhantomData;

use time::now_utc;

Expand All @@ -22,7 +23,9 @@ pub struct Response<'a, W = Fresh> {
// The status code for the request.
status: status::StatusCode,
// The outgoing headers on this response.
headers: header::Headers
headers: header::Headers,

_marker: PhantomData<W>
}

impl<'a, W> Response<'a, W> {
Expand All @@ -42,7 +45,8 @@ impl<'a, W> Response<'a, W> {
status: status,
version: version,
body: body,
headers: headers
headers: headers,
_marker: PhantomData,
}
}

Expand All @@ -60,7 +64,8 @@ impl<'a> Response<'a, Fresh> {
status: status::StatusCode::Ok,
version: version::HttpVersion::Http11,
headers: header::Headers::new(),
body: ThroughWriter(stream)
body: ThroughWriter(stream),
_marker: PhantomData,
}
}

Expand Down Expand Up @@ -119,7 +124,8 @@ impl<'a> Response<'a, Fresh> {
version: self.version,
body: stream,
status: self.status,
headers: self.headers
headers: self.headers,
_marker: PhantomData,
})
}

Expand Down

0 comments on commit 1904c45

Please sign in to comment.