summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Platte <jplatte+git@posteo.de>2024-09-11 21:17:25 +0200
committerJonas Platte <jplatte+git@posteo.de>2024-09-12 12:09:21 +0200
commitde9290a8b7fc225360b0214fb9b6bd6059dd8935 (patch)
tree8d635d164aac4e89fb98759ee50b2af6fd97a00f
parent8b1cad656fc847c4bc570e1cb53de42d333d07bf (diff)
Add more must_use attributes (#2846)
… so people get a warning when they accidentally add a semicolon after the response expression in a handler function. Also update changelogs of axum-core, axum-extra.
-rw-r--r--axum-core/CHANGELOG.md13
-rw-r--r--axum-core/src/response/into_response.rs1
-rw-r--r--axum-core/src/response/into_response_parts.rs4
-rw-r--r--axum-core/src/response/mod.rs1
-rw-r--r--axum-extra/CHANGELOG.md4
-rw-r--r--axum-extra/src/response/attachment.rs2
6 files changed, 21 insertions, 4 deletions
diff --git a/axum-core/CHANGELOG.md b/axum-core/CHANGELOG.md
index 1544fff8..be3e53ea 100644
--- a/axum-core/CHANGELOG.md
+++ b/axum-core/CHANGELOG.md
@@ -7,9 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased
-- **added:** Implement `Copy` for `DefaultBodyLimit`
+- **added:** Derive `Clone` and `Copy` for `AppendHeaders` ([#2776])
+- **added:** `must_use` attribute on `AppendHeaders` ([#2846])
+- **added:** `must_use` attribute on `ErrorResponse` ([#2846])
+- **added:** `must_use` attribute on `IntoResponse::into_response` ([#2846])
+- **added:** `must_use` attribute on `IntoResponseParts` trait methods ([#2846])
+- **added:** Implement `Copy` for `DefaultBodyLimit` ([#2875])
- **added**: `DefaultBodyLimit::max` and `DefaultBodyLimit::disable` are now
- allowed in const context
+ allowed in const context ([#2875])
+
+[#2776]: https://github.com/tokio-rs/axum/pull/2776
+[#2846]: https://github.com/tokio-rs/axum/pull/2846
+[#2875]: https://github.com/tokio-rs/axum/pull/2875
# 0.4.3 (13. January, 2024)
diff --git a/axum-core/src/response/into_response.rs b/axum-core/src/response/into_response.rs
index 679b0cbb..915b55ef 100644
--- a/axum-core/src/response/into_response.rs
+++ b/axum-core/src/response/into_response.rs
@@ -111,6 +111,7 @@ use std::{
/// ```
pub trait IntoResponse {
/// Create a response.
+ #[must_use]
fn into_response(self) -> Response;
}
diff --git a/axum-core/src/response/into_response_parts.rs b/axum-core/src/response/into_response_parts.rs
index 72b61bc7..95564823 100644
--- a/axum-core/src/response/into_response_parts.rs
+++ b/axum-core/src/response/into_response_parts.rs
@@ -105,21 +105,25 @@ pub struct ResponseParts {
impl ResponseParts {
/// Gets a reference to the response headers.
+ #[must_use]
pub fn headers(&self) -> &HeaderMap {
self.res.headers()
}
/// Gets a mutable reference to the response headers.
+ #[must_use]
pub fn headers_mut(&mut self) -> &mut HeaderMap {
self.res.headers_mut()
}
/// Gets a reference to the response extensions.
+ #[must_use]
pub fn extensions(&self) -> &Extensions {
self.res.extensions()
}
/// Gets a mutable reference to the response extensions.
+ #[must_use]
pub fn extensions_mut(&mut self) -> &mut Extensions {
self.res.extensions_mut()
}
diff --git a/axum-core/src/response/mod.rs b/axum-core/src/response/mod.rs
index 6b66c60e..dd6728b1 100644
--- a/axum-core/src/response/mod.rs
+++ b/axum-core/src/response/mod.rs
@@ -117,6 +117,7 @@ where
///
/// See [`Result`] for more details.
#[derive(Debug)]
+#[must_use]
pub struct ErrorResponse(Response);
impl<T> From<T> for ErrorResponse
diff --git a/axum-extra/CHANGELOG.md b/axum-extra/CHANGELOG.md
index 4d49aab5..2936da58 100644
--- a/axum-extra/CHANGELOG.md
+++ b/axum-extra/CHANGELOG.md
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning].
# Unreleased
-- None.
+- **added:** The `response::Attachment` type ([#2789])
+
+[#2789]: https://github.com/tokio-rs/axum/pull/2789
# 0.9.3 (24. March, 2024)
diff --git a/axum-extra/src/response/attachment.rs b/axum-extra/src/response/attachment.rs
index 923ad991..2063d30f 100644
--- a/axum-extra/src/response/attachment.rs
+++ b/axum-extra/src/response/attachment.rs
@@ -33,8 +33,8 @@ use tracing::error;
/// # Note
///
/// If you use axum with hyper, hyper will set the `Content-Length` if it is known.
-///
#[derive(Debug)]
+#[must_use]
pub struct Attachment<T> {
inner: T,
filename: Option<HeaderValue>,