Skip to content

Commit

Permalink
feat(client): Response.status() now returns a StatusCode
Browse files Browse the repository at this point in the history
Previously, it would return `&StatusCode`. Returning a reference was
actually bigger than the enum itself, and prevented using `Into` on the
return result directly.

BREAKING CHANGE: If you were explicitly checking the status, such as
  with an equality comparison, you will need to use the value instead of a
  reference.
  • Loading branch information
seanmonstar committed Mar 31, 2017
1 parent 47f3aa6 commit d63b7de
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/client/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<B> Request<B> {

/// Read the Request Version.
#[inline]
pub fn version(&self) -> &HttpVersion { &self.version }
pub fn version(&self) -> HttpVersion { self.version }

/// Read the Request headers.
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ impl Response {

/// Get the status from the server.
#[inline]
pub fn status(&self) -> &status::StatusCode { &self.status }
pub fn status(&self) -> status::StatusCode { self.status }

/// Get the raw status code and reason.
#[inline]
pub fn status_raw(&self) -> &RawStatus { &self.status_raw }

/// Get the HTTP version of this response from the server.
#[inline]
pub fn version(&self) -> &version::HttpVersion { &self.version }
pub fn version(&self) -> version::HttpVersion { self.version }

/// Take the `Body` of this response.
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/server/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ impl Request {

/// The version of HTTP for this request.
#[inline]
pub fn version(&self) -> &HttpVersion { &self.version }
pub fn version(&self) -> HttpVersion { self.version }

/// The remote socket address of this request
///
/// This is an `Option`, because some underlying transports may not have
/// a socket address, such as Unix Sockets.
#[inline]
pub fn remote_addr(&self) -> Option<&SocketAddr> { self.remote_addr.as_ref() }
pub fn remote_addr(&self) -> Option<SocketAddr> { self.remote_addr }

/// The target path of this Request.
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/server/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ impl<B> Response<B> {

/// The status of this response.
#[inline]
pub fn status(&self) -> &StatusCode {
&self.head.subject
pub fn status(&self) -> StatusCode {
self.head.subject
}

/// The HTTP version of this response.
#[inline]
pub fn version(&self) -> &version::HttpVersion { &self.head.version }
pub fn version(&self) -> version::HttpVersion { self.head.version }

/// Get a mutable reference to the Headers.
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,9 @@ impl Default for StatusCode {
}
}

impl Into<u16> for StatusCode {
fn into(self) -> u16 {
self.to_u16()
impl From<StatusCode> for u16 {
fn from(code: StatusCode) -> u16 {
code.to_u16()
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ macro_rules! test {
let work = res.join(rx).map(|r| r.0);

let res = core.run(work).unwrap();
assert_eq!(res.status(), &StatusCode::$client_status, "status is invalid");
assert_eq!(res.status(), StatusCode::$client_status, "status is invalid");
$(
assert_eq!(res.headers().get(), Some(&$response_headers), "headers are invalid");
)*
Expand Down

0 comments on commit d63b7de

Please sign in to comment.