Skip to content

Commit 374b948

Browse files
authored
Use async closures where applicable (rust-lang#10657)
1 parent 2db10be commit 374b948

File tree

7 files changed

+18
-21
lines changed

7 files changed

+18
-21
lines changed

crates/crates_io_tarball/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ mod tests {
326326

327327
#[tokio::test]
328328
async fn process_tarball_test_incorrect_manifest_casing() {
329-
let process = |file| async move {
329+
let process = async |file| {
330330
let tarball = TarballBuilder::new()
331331
.add_file(&format!("foo-0.0.1/{file}"), MANIFEST)
332332
.build();
@@ -343,7 +343,7 @@ mod tests {
343343

344344
#[tokio::test]
345345
async fn process_tarball_test_multiple_manifests() {
346-
let process = |files: Vec<_>| async move {
346+
let process = async |files: Vec<_>| {
347347
let tarball = files
348348
.iter()
349349
.fold(TarballBuilder::new(), |builder, file| {

crates/crates_io_worker/src/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<Context: Clone + Send + Sync + 'static> Worker<Context> {
7575
let job_id = job.id;
7676
debug!("Running job…");
7777

78-
let future = with_sentry_transaction(&job.job_type, || async {
78+
let future = with_sentry_transaction(&job.job_type, async || {
7979
let run_task_fn = job_registry
8080
.get(&job.job_type)
8181
.ok_or_else(|| anyhow!("Unknown job type {}", job.job_type))?;

src/controllers/krate/delete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ mod tests {
236236

237237
#[tokio::test]
238238
async fn test_query_params() -> anyhow::Result<()> {
239-
let check = |uri| async move {
239+
let check = async |uri| {
240240
let request = Request::builder().uri(uri).body(())?;
241241
let (mut parts, _) = request.into_parts();
242242
Ok::<_, anyhow::Error>(parts.extract::<DeleteQueryParams>().await?)

src/controllers/krate/publish.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,11 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<Go
527527
git_index_job.enqueue(conn),
528528
sparse_index_job.enqueue(conn),
529529
publish_notifications_job.enqueue(conn),
530-
crate_feed_job.enqueue(conn).or_else(|error| async move {
530+
crate_feed_job.enqueue(conn).or_else(async |error| {
531531
error!("Failed to enqueue `rss::SyncCrateFeed` job: {error}");
532532
Ok::<_, EnqueueError>(None)
533533
}),
534-
updates_feed_job.enqueue(conn).or_else(|error| async move {
534+
updates_feed_job.enqueue(conn).or_else(async |error| {
535535
error!("Failed to enqueue `rss::SyncUpdatesFeed` job: {error}");
536536
Ok::<_, EnqueueError>(None)
537537
}),
@@ -543,11 +543,11 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<Go
543543
let typosquat_job = CheckTyposquat::new(&krate.name);
544544

545545
tokio::try_join!(
546-
crates_feed_job.enqueue(conn).or_else(|error| async move {
546+
crates_feed_job.enqueue(conn).or_else(async |error| {
547547
error!("Failed to enqueue `rss::SyncCratesFeed` job: {error}");
548548
Ok::<_, EnqueueError>(None)
549549
}),
550-
typosquat_job.enqueue(conn).or_else(|error| async move {
550+
typosquat_job.enqueue(conn).or_else(async |error| {
551551
error!("Failed to enqueue `CheckTyposquat` job: {error}");
552552
Ok::<_, EnqueueError>(None)
553553
}),

src/middleware/cargo_compat.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,20 @@ mod tests {
142142
use tower::ServiceExt;
143143

144144
fn build_app() -> Router {
145-
let okay = get(|| async { "Everything is okay" });
146-
let teapot = get(|| async { (StatusCode::IM_A_TEAPOT, "I'm a teapot") });
147-
let internal =
148-
get(|| async { (StatusCode::INTERNAL_SERVER_ERROR, "Internal Server Error") });
145+
let okay = get(async || "Everything is okay");
146+
let teapot = get(async || (StatusCode::IM_A_TEAPOT, "I'm a teapot"));
147+
let internal = get(async || (StatusCode::INTERNAL_SERVER_ERROR, "Internal Server Error"));
149148

150149
Router::new()
151150
.route("/api/ok", okay.clone())
152151
.route("/api/teapot", teapot.clone())
153152
.route("/teapot", teapot)
154153
.route("/api/500", internal.clone())
155154
.route("/500", internal)
156-
.route("/api/v1/crates/new", put(|| async { StatusCode::CREATED }))
155+
.route("/api/v1/crates/new", put(async || StatusCode::CREATED))
157156
.route(
158157
"/api/v1/crates/{crate_id}/owners",
159-
get(|| async { StatusCode::INTERNAL_SERVER_ERROR }),
158+
get(async || StatusCode::INTERNAL_SERVER_ERROR),
160159
)
161160
.layer(from_fn_with_state(StatusCodeConfig::AdjustAll, middleware))
162161
}

src/router.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,10 @@ pub fn build_axum_router(state: AppState) -> Router<()> {
110110
}
111111

112112
router
113-
.route("/api/openapi.json", get(|| async { Json(openapi) }))
114-
.fallback(|method: Method| async move {
115-
match method {
116-
Method::HEAD => StatusCode::NOT_FOUND.into_response(),
117-
_ => not_found().into_response(),
118-
}
113+
.route("/api/openapi.json", get(async || Json(openapi)))
114+
.fallback(async |method: Method| match method {
115+
Method::HEAD => StatusCode::NOT_FOUND.into_response(),
116+
_ => not_found().into_response(),
119117
})
120118
.with_state(state)
121119
}

src/worker/jobs/archive_version_downloads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ async fn upload(
191191

192192
let directory = directory.as_ref();
193193
let uploaded_dates = futures_util::stream::iter(dates)
194-
.map(|date| async move {
194+
.map(async |date| {
195195
let path = directory.join(format!("{date}.csv"));
196196
let result = upload_file(store, &path).await;
197197
result.map(|_| date).inspect_err(|error| {

0 commit comments

Comments
 (0)