Skip to content

Commit 5faa010

Browse files
committed
Rename Redirect::found to Redirect::new to make it more default sounding
1 parent 16d3b63 commit 5faa010

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

examples/redirect.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ async fn main() -> Result<(), std::io::Error> {
66
app.at("/").get(|_| async move { Ok("Root") });
77

88
// Redirect hackers to YouTube.
9-
app.at("/.env").get(Redirect::see_other(
10-
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
11-
));
9+
app.at("/.env")
10+
.get(Redirect::new("https://www.youtube.com/watch?v=dQw4w9WgXcQ"));
1211

1312
app.at("/users-page").get(|_| async move {
1413
Ok(if signed_in() {
1514
Response::new(StatusCode::Ok)
1615
} else {
1716
// If the user is not signed in then lets redirect them to home page.
18-
Redirect::see_other("/").into()
17+
Redirect::new("/").into()
1918
})
2019
});
2120

src/redirect.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ pub struct Redirect<T: AsRef<str>> {
2828
}
2929

3030
impl<T: AsRef<str>> Redirect<T> {
31-
/// Creates an endpoint that represents a found redirect to `location`.
31+
/// Creates an endpoint that represents a redirect to `location`.
32+
///
33+
/// Uses status code 302 Found.
3234
///
3335
/// # Example
3436
///
@@ -38,14 +40,14 @@ impl<T: AsRef<str>> Redirect<T> {
3840
/// # #[allow(dead_code)]
3941
/// async fn route_handler(request: Request<()>) -> tide::Result {
4042
/// if let Some(product_url) = next_product() {
41-
/// Ok(Redirect::found(product_url).into())
43+
/// Ok(Redirect::new(product_url).into())
4244
/// } else {
4345
/// //...
4446
/// # Ok(Response::new(StatusCode::Ok)) //...
4547
/// }
4648
/// }
4749
/// ```
48-
pub fn found(location: T) -> Self {
50+
pub fn new(location: T) -> Self {
4951
Self {
5052
status: StatusCode::SeeOther,
5153
location,

src/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Response {
6767
/// }
6868
/// ```
6969
pub fn redirect(location: impl AsRef<str>) -> Self {
70-
Redirect::found(location).into()
70+
Redirect::new(location).into()
7171
}
7272

7373
/// Returns the statuscode.

0 commit comments

Comments
 (0)