Skip to content

Commit

Permalink
Add more must_use attributes
Browse files Browse the repository at this point in the history
… so people get a warning when they accidentally add a semicolon after
the response expression in a handler function.
  • Loading branch information
jplatte committed Jul 24, 2024
1 parent 5027472 commit 3b5fffa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions axum-core/src/response/into_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ use std::{
/// ```
pub trait IntoResponse {
/// Create a response.
#[must_use]
fn into_response(self) -> Response;
}

Expand Down
4 changes: 4 additions & 0 deletions axum-core/src/response/into_response_parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions axum-core/src/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ where
///
/// See [`Result`] for more details.
#[derive(Debug)]
#[must_use]
pub struct ErrorResponse(Response);

impl<T> From<T> for ErrorResponse
Expand Down
2 changes: 1 addition & 1 deletion axum-extra/src/response/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down

0 comments on commit 3b5fffa

Please sign in to comment.