Skip to content

Commit

Permalink
Avoid reallocation for String body extraction (#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhx-12243 committed Sep 20, 2024
1 parent 352b7cf commit 42003c0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion axum-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ __private_docs = ["dep:tower-http"]

[dependencies]
async-trait = "0.1.67"
bytes = "1.0"
bytes = "1.2"
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
http = "1.0.0"
http-body = "1.0.0"
Expand Down
4 changes: 1 addition & 3 deletions axum-core/src/extract/request_parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ where
}
})?;

let string = std::str::from_utf8(&bytes)
.map_err(InvalidUtf8::from_err)?
.to_owned();
let string = String::from_utf8(bytes.into()).map_err(InvalidUtf8::from_err)?;

Ok(string)
}
Expand Down

0 comments on commit 42003c0

Please sign in to comment.