Skip to content

Commit 9fd5d56

Browse files
committed
controllers::version::downloads: Use json! macro to simplify JSON serialization code
1 parent 37f111a commit 9fd5d56

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/controllers/version/downloads.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ pub fn download(req: &mut dyn RequestExt) -> EndpointResult {
9999
}
100100

101101
if req.wants_json() {
102-
#[derive(Serialize)]
103-
struct R {
104-
url: String,
105-
}
106-
Ok(req.json(&R { url: redirect_url }))
102+
Ok(req.json(&json!({ "url": redirect_url })))
107103
} else {
108104
Ok(req.redirect(redirect_url))
109105
}
@@ -129,13 +125,7 @@ pub fn downloads(req: &mut dyn RequestExt) -> EndpointResult {
129125
.load(&*conn)?
130126
.into_iter()
131127
.map(VersionDownload::into)
132-
.collect();
128+
.collect::<Vec<EncodableVersionDownload>>();
133129

134-
#[derive(Serialize)]
135-
struct R {
136-
version_downloads: Vec<EncodableVersionDownload>,
137-
}
138-
Ok(req.json(&R {
139-
version_downloads: downloads,
140-
}))
130+
Ok(req.json(&json!({ "version_downloads": downloads })))
141131
}

0 commit comments

Comments
 (0)