Skip to content

Commit d63b7de

Browse files
committed
feat(client): Response.status() now returns a StatusCode
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.
1 parent 47f3aa6 commit d63b7de

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

src/client/request.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<B> Request<B> {
3636

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

4141
/// Read the Request headers.
4242
#[inline]

src/client/response.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ impl Response {
3737

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

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

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

5050
/// Take the `Body` of this response.
5151
#[inline]

src/server/request.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ impl Request {
3737

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

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

4949
/// The target path of this Request.
5050
#[inline]

src/server/response.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ impl<B> Response<B> {
2626

2727
/// The status of this response.
2828
#[inline]
29-
pub fn status(&self) -> &StatusCode {
30-
&self.head.subject
29+
pub fn status(&self) -> StatusCode {
30+
self.head.subject
3131
}
3232

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

3737
/// Get a mutable reference to the Headers.
3838
#[inline]

src/status.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,9 @@ impl Default for StatusCode {
550550
}
551551
}
552552

553-
impl Into<u16> for StatusCode {
554-
fn into(self) -> u16 {
555-
self.to_u16()
553+
impl From<StatusCode> for u16 {
554+
fn from(code: StatusCode) -> u16 {
555+
code.to_u16()
556556
}
557557
}
558558

tests/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ macro_rules! test {
8989
let work = res.join(rx).map(|r| r.0);
9090

9191
let res = core.run(work).unwrap();
92-
assert_eq!(res.status(), &StatusCode::$client_status, "status is invalid");
92+
assert_eq!(res.status(), StatusCode::$client_status, "status is invalid");
9393
$(
9494
assert_eq!(res.headers().get(), Some(&$response_headers), "headers are invalid");
9595
)*

0 commit comments

Comments
 (0)