Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ lossy_float_literal = "warn"
macro_use_imports = "warn"
match_wildcard_for_single_variants = "warn"
mem_forget = "warn"
must_use_candidate = "warn"
needless_borrow = "warn"
needless_continue = "warn"
option_option = "warn"
rest_pat_in_fully_bound_structs = "warn"
return_self_not_must_use = "warn"
str_to_string = "warn"
suboptimal_flops = "warn"
todo = "warn"
Expand Down
2 changes: 2 additions & 0 deletions axum-core/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ where
}

/// The body type used in axum requests and responses.
#[must_use]
#[derive(Debug)]
pub struct Body(BoxBody);

Expand Down Expand Up @@ -135,6 +136,7 @@ impl http_body::Body for Body {
/// A stream of data frames.
///
/// Created with [`Body::into_data_stream`].
#[must_use]
#[derive(Debug)]
pub struct BodyDataStream {
inner: Body,
Expand Down
1 change: 1 addition & 0 deletions axum-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl Error {
}

/// Convert an `Error` back into the underlying boxed trait object.
#[must_use]
pub fn into_inner(self) -> BoxError {
self.inner
}
Expand Down
4 changes: 4 additions & 0 deletions axum-core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ macro_rules! __define_rejection {
}

/// Get the response body text used for this rejection.
#[must_use]
pub fn body_text(&self) -> String {
self.to_string()
}

/// Get the status code used for this rejection.
#[must_use]
pub fn status(&self) -> http::StatusCode {
http::StatusCode::$status
}
Expand Down Expand Up @@ -179,6 +181,7 @@ macro_rules! __composite_rejection {

impl $name {
/// Get the response body text used for this rejection.
#[must_use]
pub fn body_text(&self) -> String {
match self {
$(
Expand All @@ -188,6 +191,7 @@ macro_rules! __composite_rejection {
}

/// Get the status code used for this rejection.
#[must_use]
pub fn status(&self) -> http::StatusCode {
match self {
$(
Expand Down
4 changes: 2 additions & 2 deletions axum-extra/src/extract/cookie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub use cookie::Key;
/// .route("/me", get(me));
/// # let app: Router = app;
/// ```
#[must_use = "`CookieJar` should be returned as part of a `Response`, otherwise it does nothing."]
#[derive(Debug, Default, Clone)]
pub struct CookieJar {
jar: cookie::CookieJar,
Expand Down Expand Up @@ -153,6 +154,7 @@ impl CookieJar {
/// .map(|cookie| cookie.value().to_owned());
/// }
/// ```
#[must_use]
pub fn get(&self, name: &str) -> Option<&Cookie<'static>> {
self.jar.get(name)
}
Expand All @@ -169,7 +171,6 @@ impl CookieJar {
/// jar.remove(Cookie::from("foo"))
/// }
/// ```
#[must_use]
pub fn remove<C: Into<Cookie<'static>>>(mut self, cookie: C) -> Self {
self.jar.remove(cookie);
self
Expand All @@ -189,7 +190,6 @@ impl CookieJar {
/// jar.add(Cookie::new("foo", "bar"))
/// }
/// ```
#[must_use]
#[allow(clippy::should_implement_trait)]
pub fn add<C: Into<Cookie<'static>>>(mut self, cookie: C) -> Self {
self.jar.add(cookie);
Expand Down
6 changes: 4 additions & 2 deletions axum-extra/src/extract/cookie/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ use std::{convert::Infallible, fmt, marker::PhantomData};
/// }
/// }
/// ```
#[must_use = "`PrivateCookieJar` should be returned as part of a `Response`, otherwise it does nothing."]
pub struct PrivateCookieJar<K = Key> {
jar: cookie::CookieJar,
key: Key,
Expand Down Expand Up @@ -201,6 +202,7 @@ impl<K> PrivateCookieJar<K> {
/// .map(|cookie| cookie.value().to_owned());
/// }
/// ```
#[must_use]
pub fn get(&self, name: &str) -> Option<Cookie<'static>> {
self.private_jar().get(name)
}
Expand All @@ -217,7 +219,6 @@ impl<K> PrivateCookieJar<K> {
/// jar.remove(Cookie::from("foo"))
/// }
/// ```
#[must_use]
pub fn remove<C: Into<Cookie<'static>>>(mut self, cookie: C) -> Self {
self.private_jar_mut().remove(cookie);
self
Expand All @@ -237,7 +238,6 @@ impl<K> PrivateCookieJar<K> {
/// jar.add(Cookie::new("foo", "bar"))
/// }
/// ```
#[must_use]
#[allow(clippy::should_implement_trait)]
pub fn add<C: Into<Cookie<'static>>>(mut self, cookie: C) -> Self {
self.private_jar_mut().add(cookie);
Expand All @@ -246,6 +246,7 @@ impl<K> PrivateCookieJar<K> {

/// Authenticates and decrypts `cookie`, returning the plaintext version if decryption succeeds
/// or `None` otherwise.
#[must_use]
pub fn decrypt(&self, cookie: Cookie<'static>) -> Option<Cookie<'static>> {
self.private_jar().decrypt(cookie)
}
Expand Down Expand Up @@ -284,6 +285,7 @@ impl<K> IntoResponse for PrivateCookieJar<K> {
}
}

#[must_use = "iterators are lazy and do nothing unless consumed"]
struct PrivateCookieJarIter<'a, K> {
jar: &'a PrivateCookieJar<K>,
iter: cookie::Iter<'a>,
Expand Down
6 changes: 4 additions & 2 deletions axum-extra/src/extract/cookie/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ use std::{convert::Infallible, fmt, marker::PhantomData};
/// }
/// }
/// ```
#[must_use = "`SignedCookieJar` should be returned as part of a `Response`, otherwise it does nothing."]
pub struct SignedCookieJar<K = Key> {
jar: cookie::CookieJar,
key: Key,
Expand Down Expand Up @@ -219,6 +220,7 @@ impl<K> SignedCookieJar<K> {
/// .map(|cookie| cookie.value().to_owned());
/// }
/// ```
#[must_use]
pub fn get(&self, name: &str) -> Option<Cookie<'static>> {
self.signed_jar().get(name)
}
Expand All @@ -235,7 +237,6 @@ impl<K> SignedCookieJar<K> {
/// jar.remove(Cookie::from("foo"))
/// }
/// ```
#[must_use]
pub fn remove<C: Into<Cookie<'static>>>(mut self, cookie: C) -> Self {
self.signed_jar_mut().remove(cookie);
self
Expand All @@ -255,7 +256,6 @@ impl<K> SignedCookieJar<K> {
/// jar.add(Cookie::new("foo", "bar"))
/// }
/// ```
#[must_use]
#[allow(clippy::should_implement_trait)]
pub fn add<C: Into<Cookie<'static>>>(mut self, cookie: C) -> Self {
self.signed_jar_mut().add(cookie);
Expand All @@ -264,6 +264,7 @@ impl<K> SignedCookieJar<K> {

/// Verifies the authenticity and integrity of `cookie`, returning the plaintext version if
/// verification succeeds or `None` otherwise.
#[must_use]
pub fn verify(&self, cookie: Cookie<'static>) -> Option<Cookie<'static>> {
self.signed_jar().verify(cookie)
}
Expand Down Expand Up @@ -302,6 +303,7 @@ impl<K> IntoResponse for SignedCookieJar<K> {
}
}

#[must_use = "iterators are lazy and do nothing unless consumed"]
struct SignedCookieJarIter<'a, K> {
jar: &'a SignedCookieJar<K>,
iter: cookie::Iter<'a>,
Expand Down
5 changes: 5 additions & 0 deletions axum-extra/src/extract/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,27 @@ impl Field {
/// The field name found in the
/// [`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)
/// header.
#[must_use]
pub fn name(&self) -> Option<&str> {
self.inner.name()
}

/// The file name found in the
/// [`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)
/// header.
#[must_use]
pub fn file_name(&self) -> Option<&str> {
self.inner.file_name()
}

/// Get the [content type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) of the field.
#[must_use]
pub fn content_type(&self) -> Option<&str> {
self.inner.content_type().map(|m| m.as_ref())
}

/// Get a map of headers as [`HeaderMap`].
#[must_use]
pub fn headers(&self) -> &HeaderMap {
self.inner.headers()
}
Expand Down Expand Up @@ -253,6 +257,7 @@ impl MultipartError {
}

/// Get the status code used for this rejection.
#[must_use]
pub fn status(&self) -> http::StatusCode {
status_code_from_multer_error(&self.source)
}
Expand Down
1 change: 1 addition & 0 deletions axum-extra/src/response/file_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use tokio_util::io::ReaderStream;
/// let app = Router::new().route("/file-stream", get(file_stream));
/// # let _: Router = app;
/// ```
#[must_use]
#[derive(Debug)]
pub struct FileStream<S> {
/// stream.
Expand Down
3 changes: 3 additions & 0 deletions axum-extra/src/response/multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use mime::Mime;
/// Create multipart forms to be used in API responses.
///
/// This struct implements [`IntoResponse`], and so it can be returned from a handler.
#[must_use]
#[derive(Debug)]
pub struct MultipartForm {
parts: Vec<Part>,
Expand Down Expand Up @@ -103,6 +104,7 @@ impl Part {
/// let parts: Vec<Part> = vec![Part::text("foo".to_string(), "abc")];
/// let form = MultipartForm::from_iter(parts);
/// ```
#[must_use]
pub fn text(name: String, contents: &str) -> Self {
Self {
name,
Expand All @@ -127,6 +129,7 @@ impl Part {
/// let parts: Vec<Part> = vec![Part::file("foo", "foo.txt", vec![0x68, 0x68, 0x20, 0x6d, 0x6f, 0x6d])];
/// let form = MultipartForm::from_iter(parts);
/// ```
#[must_use]
pub fn file(field_name: &str, file_name: &str, contents: Vec<u8>) -> Self {
Self {
name: field_name.to_owned(),
Expand Down
2 changes: 2 additions & 0 deletions axum-extra/src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub use self::typed::{SecondElementIs, TypedPath};
// Validates a path at compile time, used with the vpath macro.
#[rustversion::since(1.80)]
#[doc(hidden)]
#[must_use]
pub const fn __private_validate_static_path(path: &'static str) -> &'static str {
if path.is_empty() {
panic!("Paths must start with a `/`. Use \"/\" for root routes")
Expand Down Expand Up @@ -76,6 +77,7 @@ macro_rules! vpath {
}

/// Extension trait that adds additional methods to [`Router`].
#[allow(clippy::return_self_not_must_use)]
pub trait RouterExt<S>: sealed::Sealed {
/// Add a typed `GET` route to the router.
///
Expand Down
2 changes: 2 additions & 0 deletions axum-extra/src/typed_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ pub struct TypedHeaderRejection {

impl TypedHeaderRejection {
/// Name of the header that caused the rejection
#[must_use]
pub fn name(&self) -> &http::header::HeaderName {
self.name
}

/// Reason why the header extraction has failed
#[must_use]
pub fn reason(&self) -> &TypedHeaderRejectionReason {
&self.reason
}
Expand Down
1 change: 1 addition & 0 deletions axum/src/extract/matched_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct MatchedPath(pub(crate) Arc<str>);

impl MatchedPath {
/// Returns a `str` representation of the path.
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
Expand Down
6 changes: 6 additions & 0 deletions axum/src/extract/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,27 @@ impl Field<'_> {
/// The field name found in the
/// [`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)
/// header.
#[must_use]
pub fn name(&self) -> Option<&str> {
self.inner.name()
}

/// The file name found in the
/// [`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)
/// header.
#[must_use]
pub fn file_name(&self) -> Option<&str> {
self.inner.file_name()
}

/// Get the [content type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) of the field.
#[must_use]
pub fn content_type(&self) -> Option<&str> {
self.inner.content_type().map(|m| m.as_ref())
}

/// Get a map of headers as [`HeaderMap`].
#[must_use]
pub fn headers(&self) -> &HeaderMap {
self.inner.headers()
}
Expand Down Expand Up @@ -238,11 +242,13 @@ impl MultipartError {
}

/// Get the response body text used for this rejection.
#[must_use]
pub fn body_text(&self) -> String {
self.source.to_string()
}

/// Get the status code used for this rejection.
#[must_use]
pub fn status(&self) -> http::StatusCode {
status_code_from_multer_error(&self.source)
}
Expand Down
1 change: 1 addition & 0 deletions axum/src/extract/nested_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct NestedPath(Arc<str>);

impl NestedPath {
/// Returns a `str` representation of the path.
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
Expand Down
6 changes: 6 additions & 0 deletions axum/src/extract/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ impl std::error::Error for PathDeserializationError {}
/// This type is obtained through [`FailedToDeserializePathParams::kind`] or
/// [`FailedToDeserializePathParams::into_kind`] and is useful for building
/// more precise error messages.
#[must_use]
#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ErrorKind {
Expand Down Expand Up @@ -417,6 +418,7 @@ impl FailedToDeserializePathParams {
}

/// Get the response body text used for this rejection.
#[must_use]
pub fn body_text(&self) -> String {
match self.0.kind {
ErrorKind::Message(_)
Expand All @@ -432,6 +434,7 @@ impl FailedToDeserializePathParams {
}

/// Get the status code used for this rejection.
#[must_use]
pub fn status(&self) -> StatusCode {
match self.0.kind {
ErrorKind::Message(_)
Expand Down Expand Up @@ -523,6 +526,7 @@ where

impl RawPathParams {
/// Get an iterator over the path parameters.
#[must_use]
pub fn iter(&self) -> RawPathParamsIter<'_> {
self.into_iter()
}
Expand Down Expand Up @@ -561,11 +565,13 @@ pub struct InvalidUtf8InPathParam {

impl InvalidUtf8InPathParam {
/// Get the response body text used for this rejection.
#[must_use]
pub fn body_text(&self) -> String {
self.to_string()
}

/// Get the status code used for this rejection.
#[must_use]
pub fn status(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
Expand Down
Loading
Loading