From 6f50c6ed4e28677501eddfa2487fe20640a66862 Mon Sep 17 00:00:00 2001 From: StNicolay <103897650+StNicolay@users.noreply.github.com> Date: Fri, 16 Aug 2024 11:12:35 +0300 Subject: [PATCH] Made DefaultBodyLimit const friendly (#2875) --- axum-core/CHANGELOG.md | 4 +++- axum-core/src/extract/default_body_limit.rs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/axum-core/CHANGELOG.md b/axum-core/CHANGELOG.md index ef0d1a67..1544fff8 100644 --- a/axum-core/CHANGELOG.md +++ b/axum-core/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased -- None. +- **added:** Implement `Copy` for `DefaultBodyLimit` +- **added**: `DefaultBodyLimit::max` and `DefaultBodyLimit::disable` are now + allowed in const context # 0.4.3 (13. January, 2024) diff --git a/axum-core/src/extract/default_body_limit.rs b/axum-core/src/extract/default_body_limit.rs index 2ec82feb..a045d1cd 100644 --- a/axum-core/src/extract/default_body_limit.rs +++ b/axum-core/src/extract/default_body_limit.rs @@ -72,7 +72,7 @@ use tower_layer::Layer; /// [`RequestBodyLimit`]: tower_http::limit::RequestBodyLimit /// [`RequestExt::with_limited_body`]: crate::RequestExt::with_limited_body /// [`RequestExt::into_limited_body`]: crate::RequestExt::into_limited_body -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] #[must_use] pub struct DefaultBodyLimit { kind: DefaultBodyLimitKind, @@ -116,7 +116,7 @@ impl DefaultBodyLimit { /// [`Bytes`]: bytes::Bytes /// [`Json`]: https://docs.rs/axum/0.7/axum/struct.Json.html /// [`Form`]: https://docs.rs/axum/0.7/axum/struct.Form.html - pub fn disable() -> Self { + pub const fn disable() -> Self { Self { kind: DefaultBodyLimitKind::Disable, } @@ -149,7 +149,7 @@ impl DefaultBodyLimit { /// [`Bytes::from_request`]: bytes::Bytes /// [`Json`]: https://docs.rs/axum/0.7/axum/struct.Json.html /// [`Form`]: https://docs.rs/axum/0.7/axum/struct.Form.html - pub fn max(limit: usize) -> Self { + pub const fn max(limit: usize) -> Self { Self { kind: DefaultBodyLimitKind::Limit(limit), }