From 3e2865de1208c74ea1782d80b4a7a766e720e6e2 Mon Sep 17 00:00:00 2001 From: Emii Tatsuo Date: Tue, 1 Dec 2020 17:13:54 -0500 Subject: [PATCH] Fix ratelimiting example Geeze, that code's ancient! How long was that broken? --- examples/ratelimiting.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/examples/ratelimiting.rs b/examples/ratelimiting.rs index 455fc22..f8021cb 100644 --- a/examples/ratelimiting.rs +++ b/examples/ratelimiting.rs @@ -17,21 +17,18 @@ async fn main() -> Result<()> { .await } -fn handle_request(request: Request) -> BoxFuture<'static, Result> { - async move { - let mut document = Document::new(); +async fn handle_request(request: Request) -> Result { + let mut document = Document::new(); - if let Some("limit") = request.trailing_segments().get(0).map(String::as_str) { - document.add_text("You're on a rate limited page!") - .add_text("You can only access this page twice per minute"); - } else { - document.add_text("You're on a normal page!") - .add_text("You can access this page as much as you like."); - } - document.add_blank_line() - .add_link("/limit", "Go to rate limited page") - .add_link("/", "Go to a page that's not rate limited"); - Ok(Response::document(document)) + if let Some("limit") = request.trailing_segments().get(0).map(String::as_str) { + document.add_text("You're on a rate limited page!") + .add_text("You can only access this page twice per minute"); + } else { + document.add_text("You're on a normal page!") + .add_text("You can access this page as much as you like."); } - .boxed() + document.add_blank_line() + .add_link("/limit", "Go to rate limited page") + .add_link("/", "Go to a page that's not rate limited"); + Ok(document.into()) }