Skip to content

Commit 18382c1

Browse files
authored
publish: Skip unnecessary String::from_utf8() call (#5888)
We can use `serde_json::from_slice()` instead, which removes the need for the string conversion.
1 parent 151f69f commit 18382c1

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/controllers/krate/publish.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ fn parse_new_headers<B: Read>(req: &mut Request<B>) -> AppResult<EncodableCrateU
316316
}
317317
let mut json = vec![0; metadata_length as usize];
318318
read_fill(req.body_mut(), &mut json)?;
319-
let json = String::from_utf8(json).map_err(|_| cargo_err("json body was not valid utf-8"))?;
320-
let new: EncodableCrateUpload = serde_json::from_str(&json)
319+
let new: EncodableCrateUpload = serde_json::from_slice(&json)
321320
.map_err(|e| cargo_err(&format_args!("invalid upload request: {e}")))?;
322321

323322
// Make sure required fields are provided

0 commit comments

Comments
 (0)