Skip to content

Commit a26863a

Browse files
authored
Merge pull request #581 from jbr/no-unnecessary-move
remove unnecessary `move`s from route handlers
2 parents 1b60303 + f64858a commit a26863a

File tree

14 files changed

+22
-23
lines changed

14 files changed

+22
-23
lines changed

benches/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn criterion_benchmark(c: &mut Criterion) {
77
router.add(
88
"hello",
99
Method::Get,
10-
Box::new(|_| async move { Ok("hello world") }),
10+
Box::new(|_| async { Ok("hello world") }),
1111
);
1212

1313
c.bench_function("route-match", |b| {

examples/chunked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tide::{Body, Response, StatusCode};
44
fn main() -> Result<(), std::io::Error> {
55
task::block_on(async {
66
let mut app = tide::new();
7-
app.at("/").get(|_| async move {
7+
app.at("/").get(|_| async {
88
let mut res = Response::new(StatusCode::Ok);
99
res.set_body(Body::from_file(file!()).await.unwrap());
1010
Ok(res)

examples/hello.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
async fn main() -> Result<(), std::io::Error> {
33
tide::log::start();
44
let mut app = tide::new();
5-
app.at("/").get(|_| async move { Ok("Hello, world!") });
5+
app.at("/").get(|_| async { Ok("Hello, world!") });
66
app.listen("127.0.0.1:8080").await?;
77
Ok(())
88
}

examples/nested.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#[async_std::main]
22
async fn main() -> Result<(), std::io::Error> {
33
let mut app = tide::new();
4-
app.at("/").get(|_| async move { Ok("Root") });
4+
app.at("/").get(|_| async { Ok("Root") });
55
app.at("/api").nest({
66
let mut api = tide::new();
7-
api.at("/hello").get(|_| async move { Ok("Hello, world") });
8-
api.at("/goodbye")
9-
.get(|_| async move { Ok("Goodbye, world") });
7+
api.at("/hello").get(|_| async { Ok("Hello, world") });
8+
api.at("/goodbye").get(|_| async { Ok("Goodbye, world") });
109
api
1110
});
1211
app.listen("127.0.0.1:8080").await?;

examples/redirect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use tide::{http::StatusCode, Redirect, Response};
33
#[async_std::main]
44
async fn main() -> Result<(), std::io::Error> {
55
let mut app = tide::new();
6-
app.at("/").get(|_| async move { Ok("Root") });
6+
app.at("/").get(|_| async { Ok("Root") });
77

88
// Redirect hackers to YouTube.
99
app.at("/.env")
1010
.get(Redirect::new("https://www.youtube.com/watch?v=dQw4w9WgXcQ"));
1111

12-
app.at("/users-page").get(|_| async move {
12+
app.at("/users-page").get(|_| async {
1313
Ok(if signed_in() {
1414
Response::new(StatusCode::Ok)
1515
} else {

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
//! # fn main() -> Result<(), std::io::Error> { block_on(async {
3030
//! #
3131
//! let mut app = tide::new();
32-
//! app.at("/").get(|_| async move { Ok("Hello, world!") });
32+
//! app.at("/").get(|_| async { Ok("Hello, world!") });
3333
//! app.listen("127.0.0.1:8080").await?;
3434
//! #
3535
//! # Ok(()) }) }
@@ -41,7 +41,7 @@
4141
//! # fn main() -> Result<(), std::io::Error> { block_on(async {
4242
//! #
4343
//! let mut app = tide::new();
44-
//! app.at("/").get(|req| async move { Ok(req) });
44+
//! app.at("/").get(|req| async { Ok(req) });
4545
//! app.listen("127.0.0.1:8080").await?;
4646
//! #
4747
//! # Ok(()) }) }
@@ -233,7 +233,7 @@ pub use http_types::{self as http, Body, Error, Status, StatusCode};
233233
/// # fn main() -> Result<(), std::io::Error> { block_on(async {
234234
/// #
235235
/// let mut app = tide::new();
236-
/// app.at("/").get(|_| async move { Ok("Hello, world!") });
236+
/// app.at("/").get(|_| async { Ok("Hello, world!") });
237237
/// app.listen("127.0.0.1:8080").await?;
238238
/// #
239239
/// # Ok(()) }) }

src/redirect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! use tide::Redirect;
1010
//!
1111
//! let mut app = tide::new();
12-
//! app.at("/").get(|_| async move { Ok("meow") });
12+
//! app.at("/").get(|_| async { Ok("meow") });
1313
//! app.at("/nori").get(Redirect::temporary("/"));
1414
//! app.listen("127.0.0.1:8080").await?;
1515
//! #

src/router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ impl<State: 'static> Router<State> {
8383
}
8484

8585
fn not_found_endpoint<State>(_req: Request<State>) -> BoxFuture<'static, crate::Result> {
86-
Box::pin(async move { Ok(Response::new(StatusCode::NotFound)) })
86+
Box::pin(async { Ok(Response::new(StatusCode::NotFound)) })
8787
}
8888

8989
fn method_not_allowed<State>(_req: Request<State>) -> BoxFuture<'static, crate::Result> {
90-
Box::pin(async move { Ok(Response::new(StatusCode::MethodNotAllowed)) })
90+
Box::pin(async { Ok(Response::new(StatusCode::MethodNotAllowed)) })
9191
}

src/security/cors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ mod test {
253253

254254
fn app() -> crate::Server<()> {
255255
let mut app = crate::Server::new();
256-
app.at(ENDPOINT).get(|_| async move { Ok("Hello World") });
256+
app.at(ENDPOINT).get(|_| async { Ok("Hello World") });
257257

258258
app
259259
}

src/server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl Server<()> {
143143
/// # fn main() -> Result<(), std::io::Error> { block_on(async {
144144
/// #
145145
/// let mut app = tide::new();
146-
/// app.at("/").get(|_| async move { Ok("Hello, world!") });
146+
/// app.at("/").get(|_| async { Ok("Hello, world!") });
147147
/// app.listen("127.0.0.1:8080").await?;
148148
/// #
149149
/// # Ok(()) }) }
@@ -213,7 +213,7 @@ impl<State: Send + Sync + 'static> Server<State> {
213213
///
214214
/// ```rust,no_run
215215
/// # let mut app = tide::Server::new();
216-
/// app.at("/").get(|_| async move { Ok("Hello, world!") });
216+
/// app.at("/").get(|_| async { Ok("Hello, world!") });
217217
/// ```
218218
///
219219
/// A path is comprised of zero or many segments, i.e. non-empty strings
@@ -369,7 +369,7 @@ impl<State: Send + Sync + 'static> Server<State> {
369369
/// use tide::http::{Url, Method, Request, Response};
370370
///
371371
/// let mut app = tide::new();
372-
/// app.at("/").get(|_| async move { Ok("hello world") });
372+
/// app.at("/").get(|_| async { Ok("hello world") });
373373
///
374374
/// let req = Request::new(Method::Get, Url::parse("https://example.com")?);
375375
/// let res: Response = app.respond(req).await?;

tests/chunked-encode-small.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async fn chunked_large() -> Result<(), http_types::Error> {
2121
let port = test_utils::find_port().await;
2222
let server = task::spawn(async move {
2323
let mut app = tide::new();
24-
app.at("/").get(|_| async move {
24+
app.at("/").get(|_| async {
2525
let mut res = Response::new(StatusCode::Ok);
2626
let body = Cursor::new(TEXT.to_owned());
2727
res.set_body(Body::from_reader(body, None));

tests/nested.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async fn nested_with_different_state() {
101101
let num = req.state();
102102
Ok(format!("the number is {}", num))
103103
});
104-
outer.at("/").get(|_| async move { Ok("Hello, world!") });
104+
outer.at("/").get(|_| async { Ok("Hello, world!") });
105105
outer.at("/foo").nest(inner);
106106

107107
let req = Request::new(Method::Get, Url::parse("http://example.com/foo").unwrap());

tests/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async fn json_content_type() {
4242
use tide::Body;
4343

4444
let mut app = tide::new();
45-
app.at("/json_content_type").get(|_| async move {
45+
app.at("/json_content_type").get(|_| async {
4646
let mut map = BTreeMap::new();
4747
map.insert(Some("a"), 2);
4848
map.insert(Some("b"), 4);

tests/wildcard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async fn invalid_wildcard() {
174174
#[async_std::test]
175175
async fn nameless_wildcard() {
176176
let mut app = tide::Server::new();
177-
app.at("/echo/:").get(|_| async move { Ok("") });
177+
app.at("/echo/:").get(|_| async { Ok("") });
178178

179179
let req = http::Request::new(
180180
Method::Get,

0 commit comments

Comments
 (0)