Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RequestParts::body_mut return &mut Option<B> #869

Merged
merged 3 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions axum-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `<Request as FromRequest>::Rejection` is now `BodyAlreadyExtracted`.
- `<http::request::Parts as FromRequest>::Rejection` is now `Infallible`.
- `ExtensionsAlreadyExtracted` has been removed.
- **breaking:** `RequestParts::body_mut` now returns `&mut Option<B>` so the
body can be swapped ([#869])

[#698]: https://github.com/tokio-rs/axum/pull/698
[#699]: https://github.com/tokio-rs/axum/pull/699
[#767]: https://github.com/tokio-rs/axum/pull/767
[#797]: https://github.com/tokio-rs/axum/pull/797
[#869]: https://github.com/tokio-rs/axum/pull/869

# 0.1.1 (06. December, 2021)

Expand Down
5 changes: 3 additions & 2 deletions axum-core/src/extract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ impl<B> RequestParts<B> {
/// Gets a mutable reference to the request body.
///
/// Returns `None` if the body has been taken by another extractor.
pub fn body_mut(&mut self) -> Option<&mut B> {
self.body.as_mut()
// this returns `&mut Option<B>` rather than `Option<&mut B>` such that users can swap it
davidpdrsn marked this conversation as resolved.
Show resolved Hide resolved
pub fn body_mut(&mut self) -> &mut Option<B> {
&mut self.body
}

/// Takes the body out of the request, leaving a `None` in its place.
Expand Down