Skip to content

Commit df74cef

Browse files
committed
Simplify repetitive and inconsistent docs
1 parent f7ff11b commit df74cef

File tree

1 file changed

+19
-66
lines changed

1 file changed

+19
-66
lines changed

src/redirect.rs

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ use crate::StatusCode;
2121
use crate::{Endpoint, Request, Response};
2222

2323
/// A redirection endpoint.
24+
///
25+
/// # Example
26+
///
27+
/// ```
28+
/// # use tide::{Response, Redirect, Request, StatusCode};
29+
/// # fn next_product() -> Option<String> { None }
30+
/// # #[allow(dead_code)]
31+
/// async fn route_handler(request: Request<()>) -> tide::Result {
32+
/// if let Some(product_url) = next_product() {
33+
/// Ok(Redirect::new(product_url).into())
34+
/// } else {
35+
/// //...
36+
/// # Ok(Response::new(StatusCode::Ok)) //...
37+
/// }
38+
/// }
39+
/// ```
2440
#[derive(Debug, Clone)]
2541
pub struct Redirect<T: AsRef<str>> {
2642
status: StatusCode,
@@ -31,22 +47,6 @@ impl<T: AsRef<str>> Redirect<T> {
3147
/// Creates an endpoint that represents a redirect to `location`.
3248
///
3349
/// Uses status code 302 Found.
34-
///
35-
/// # Example
36-
///
37-
/// ```
38-
/// # use tide::{Response, Redirect, Request, StatusCode};
39-
/// # fn next_product() -> Option<String> { None }
40-
/// # #[allow(dead_code)]
41-
/// async fn route_handler(request: Request<()>) -> tide::Result {
42-
/// if let Some(product_url) = next_product() {
43-
/// Ok(Redirect::new(product_url).into())
44-
/// } else {
45-
/// //...
46-
/// # Ok(Response::new(StatusCode::Ok)) //...
47-
/// }
48-
/// }
49-
/// ```
5050
pub fn new(location: T) -> Self {
5151
Self {
5252
status: StatusCode::SeeOther,
@@ -56,22 +56,7 @@ impl<T: AsRef<str>> Redirect<T> {
5656

5757
/// Creates an endpoint that represents a permanent redirect to `location`.
5858
///
59-
///
60-
/// # Example
61-
///
62-
/// ```
63-
/// # use tide::{Response, Redirect, Request, StatusCode};
64-
/// # fn canonicalize(uri: &url::Url) -> Option<&url::Url> { None }
65-
/// # #[allow(dead_code)]
66-
/// async fn route_handler(request: Request<()>) -> tide::Result {
67-
/// if let Some(canonical_redirect) = canonicalize(request.uri()) {
68-
/// Ok(Redirect::permanent(canonical_redirect).into())
69-
/// } else {
70-
/// //...
71-
/// # Ok(Response::new(StatusCode::Ok)) // ...
72-
/// }
73-
/// }
74-
/// ```
59+
/// Uses status code 301 Permanent Redirect.
7560
pub fn permanent(location: T) -> Self {
7661
Self {
7762
status: StatusCode::PermanentRedirect,
@@ -81,22 +66,7 @@ impl<T: AsRef<str>> Redirect<T> {
8166

8267
/// Creates an endpoint that represents a temporary redirect to `location`.
8368
///
84-
///
85-
/// # Example
86-
///
87-
/// ```
88-
/// # use tide::{Response, Redirect, Request, StatusCode};
89-
/// # fn special_sale_today() -> Option<String> { None }
90-
/// # #[allow(dead_code)]
91-
/// async fn route_handler(request: Request<()>) -> tide::Result {
92-
/// if let Some(sale_url) = special_sale_today() {
93-
/// Ok(Redirect::temporary(sale_url).into())
94-
/// } else {
95-
/// //...
96-
/// # Ok(Response::new(StatusCode::Ok)) //...
97-
/// }
98-
/// }
99-
/// ```
69+
/// Uses status code 307 Temporary Redirect.
10070
pub fn temporary(location: T) -> Self {
10171
Self {
10272
status: StatusCode::TemporaryRedirect,
@@ -106,24 +76,7 @@ impl<T: AsRef<str>> Redirect<T> {
10676

10777
/// Creates an endpoint that represents a see other redirect to `location`.
10878
///
109-
/// GET methods are unchanged.
110-
/// Other methods are changed to GET and their body lost.
111-
///
112-
/// # Example
113-
///
114-
/// ```
115-
/// # use tide::{Response, Redirect, Request, StatusCode};
116-
/// # fn next_product() -> Option<String> { None }
117-
/// # #[allow(dead_code)]
118-
/// async fn route_handler(request: Request<()>) -> tide::Result {
119-
/// if let Some(product_url) = next_product() {
120-
/// Ok(Redirect::see_other(product_url).into())
121-
/// } else {
122-
/// //...
123-
/// # Ok(Response::new(StatusCode::Ok)) //...
124-
/// }
125-
/// }
126-
/// ```
79+
/// Uses status code 303 See Other.
12780
pub fn see_other(location: T) -> Self {
12881
Self {
12982
status: StatusCode::SeeOther,

0 commit comments

Comments
 (0)