Skip to content

Commit 0fc6720

Browse files
committed
Replace Redirect::response with an extra Into<Response> impl
1 parent df74cef commit 0fc6720

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/redirect.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,26 @@ impl<T: AsRef<str>> Redirect<T> {
8383
location,
8484
}
8585
}
86-
87-
/// Returns response with equivalent redirect.
88-
pub fn response(&self) -> Response {
89-
Response::new(self.status).set_header("location".parse().unwrap(), &self.location)
90-
}
9186
}
9287

9388
impl<State, T> Endpoint<State> for Redirect<T>
9489
where
9590
T: AsRef<str> + Send + Sync + 'static,
9691
{
9792
fn call<'a>(&'a self, _req: Request<State>) -> BoxFuture<'a, crate::Result<Response>> {
98-
let res = self.response();
93+
let res = self.into();
9994
Box::pin(async move { Ok(res) })
10095
}
10196
}
10297

10398
impl<T: AsRef<str>> Into<Response> for Redirect<T> {
10499
fn into(self) -> Response {
105-
self.response()
100+
(&self).into()
101+
}
102+
}
103+
104+
impl<T: AsRef<str>> Into<Response> for &Redirect<T> {
105+
fn into(self) -> Response {
106+
Response::new(self.status).set_header("location".parse().unwrap(), &self.location)
106107
}
107108
}

0 commit comments

Comments
 (0)