Skip to content

Commit a3ae780

Browse files
committed
[bitreq] Serialize Request body into Vec<u8>
We avoid creating a `String` only to immediately convert it back to its inner `Vec<u8>`. This also mirrors the `serde_json::from_slice` call made when parsing a `Response` body as JSON.
1 parent c66c615 commit a3ae780

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bitreq/src/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl Request {
190190
pub fn with_json<T: serde::ser::Serialize>(mut self, body: &T) -> Result<Request, Error> {
191191
self.headers
192192
.insert("Content-Type".to_string(), "application/json; charset=UTF-8".to_string());
193-
match serde_json::to_string(&body) {
193+
match serde_json::to_vec(&body) {
194194
Ok(json) => Ok(self.with_body(json)),
195195
Err(err) => Err(Error::SerdeJsonError(err)),
196196
}

0 commit comments

Comments
 (0)