Skip to content

Commit 0424d29

Browse files
committed
controllers::krate::search: Use json! macro to simplify JSON serialization code
1 parent f2b7e53 commit 0424d29

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/controllers/krate/search.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -338,28 +338,16 @@ pub fn search(req: &mut dyn RequestExt) -> EndpointResult {
338338
)
339339
},
340340
)
341-
.collect();
342-
343-
#[derive(Serialize)]
344-
struct R {
345-
crates: Vec<EncodableCrate>,
346-
meta: Meta,
347-
}
348-
#[derive(Serialize)]
349-
struct Meta {
350-
total: Option<i64>,
351-
next_page: Option<String>,
352-
prev_page: Option<String>,
353-
}
341+
.collect::<Vec<_>>();
354342

355-
Ok(req.json(&R {
356-
crates,
357-
meta: Meta {
358-
total: Some(total),
359-
next_page,
360-
prev_page,
343+
Ok(req.json(&json!({
344+
"crates": crates,
345+
"meta": {
346+
"total": total,
347+
"next_page": next_page,
348+
"prev_page": prev_page,
361349
},
362-
}))
350+
})))
363351
}
364352

365353
diesel_infix_operator!(Contains, "@>");

0 commit comments

Comments
 (0)