Made DefaultBodyLimit const friendly (#2875)

This commit is contained in:
StNicolay 2024-08-16 11:12:35 +03:00 committed by GitHub
parent 35c6f11c94
commit 6f50c6ed4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View file

@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased # 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) # 0.4.3 (13. January, 2024)

View file

@ -72,7 +72,7 @@ use tower_layer::Layer;
/// [`RequestBodyLimit`]: tower_http::limit::RequestBodyLimit /// [`RequestBodyLimit`]: tower_http::limit::RequestBodyLimit
/// [`RequestExt::with_limited_body`]: crate::RequestExt::with_limited_body /// [`RequestExt::with_limited_body`]: crate::RequestExt::with_limited_body
/// [`RequestExt::into_limited_body`]: crate::RequestExt::into_limited_body /// [`RequestExt::into_limited_body`]: crate::RequestExt::into_limited_body
#[derive(Debug, Clone)] #[derive(Debug, Clone, Copy)]
#[must_use] #[must_use]
pub struct DefaultBodyLimit { pub struct DefaultBodyLimit {
kind: DefaultBodyLimitKind, kind: DefaultBodyLimitKind,
@ -116,7 +116,7 @@ impl DefaultBodyLimit {
/// [`Bytes`]: bytes::Bytes /// [`Bytes`]: bytes::Bytes
/// [`Json`]: https://docs.rs/axum/0.7/axum/struct.Json.html /// [`Json`]: https://docs.rs/axum/0.7/axum/struct.Json.html
/// [`Form`]: https://docs.rs/axum/0.7/axum/struct.Form.html /// [`Form`]: https://docs.rs/axum/0.7/axum/struct.Form.html
pub fn disable() -> Self { pub const fn disable() -> Self {
Self { Self {
kind: DefaultBodyLimitKind::Disable, kind: DefaultBodyLimitKind::Disable,
} }
@ -149,7 +149,7 @@ impl DefaultBodyLimit {
/// [`Bytes::from_request`]: bytes::Bytes /// [`Bytes::from_request`]: bytes::Bytes
/// [`Json`]: https://docs.rs/axum/0.7/axum/struct.Json.html /// [`Json`]: https://docs.rs/axum/0.7/axum/struct.Json.html
/// [`Form`]: https://docs.rs/axum/0.7/axum/struct.Form.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 { Self {
kind: DefaultBodyLimitKind::Limit(limit), kind: DefaultBodyLimitKind::Limit(limit),
} }