From a0ae0c48aabcca1c93141d8a0ec4a42bb7b80122 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Fri, 18 Mar 2022 16:39:13 +0100 Subject: [PATCH] Make `RequestParts::body_mut` return `&mut Option` (#869) --- axum-core/CHANGELOG.md | 3 +++ axum-core/src/extract/mod.rs | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/axum-core/CHANGELOG.md b/axum-core/CHANGELOG.md index 2900d593..d0fdb214 100644 --- a/axum-core/CHANGELOG.md +++ b/axum-core/CHANGELOG.md @@ -37,11 +37,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `::Rejection` is now `BodyAlreadyExtracted`. - `::Rejection` is now `Infallible`. - `ExtensionsAlreadyExtracted` has been removed. +- **breaking:** `RequestParts::body_mut` now returns `&mut Option` 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) diff --git a/axum-core/src/extract/mod.rs b/axum-core/src/extract/mod.rs index 1a85da81..680234fe 100644 --- a/axum-core/src/extract/mod.rs +++ b/axum-core/src/extract/mod.rs @@ -204,8 +204,9 @@ impl RequestParts { /// 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` rather than `Option<&mut B>` such that users can use it to set the body. + pub fn body_mut(&mut self) -> &mut Option { + &mut self.body } /// Takes the body out of the request, leaving a `None` in its place.