From b1623ce7f2e0e58f9773a880d891590e564b2055 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 10 Dec 2021 22:56:56 +0100 Subject: [PATCH] Add AddExtension::layer (#607) --- axum/CHANGELOG.md | 4 +++- axum/src/add_extension.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index aa1835b5cc..a25e226c02 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased -- None. +- **added:** `axum::AddExtension::layer` ([#607]) + +[#607]: https://github.com/tokio-rs/axum/pull/607 # 0.4.2 (06. December, 2021) diff --git a/axum/src/add_extension.rs b/axum/src/add_extension.rs index 24e12b24ef..4bf88ee659 100644 --- a/axum/src/add_extension.rs +++ b/axum/src/add_extension.rs @@ -19,7 +19,7 @@ pub struct AddExtensionLayer { impl AddExtensionLayer { /// Create a new [`AddExtensionLayer`]. pub fn new(value: T) -> Self { - AddExtensionLayer { value } + Self { value } } } @@ -49,6 +49,13 @@ pub struct AddExtension { value: T, } +impl AddExtension { + /// Create a new [`AddExtensionLayer`]. + pub fn layer(value: T) -> AddExtensionLayer { + AddExtensionLayer::new(value) + } +} + impl Service> for AddExtension where S: Service>,