From 4a731904d82e6845a443fb43046ffed8ba1a2adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Sun, 22 Dec 2024 11:08:09 +0100 Subject: [PATCH] Implement middleware for &T: Middleware<_> That allows to pass middlewares with their configuration around at application setup time without having to clone them. --- poem/src/middleware/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/poem/src/middleware/mod.rs b/poem/src/middleware/mod.rs index bbc072b9a2..5cb3e0e61d 100644 --- a/poem/src/middleware/mod.rs +++ b/poem/src/middleware/mod.rs @@ -301,6 +301,14 @@ impl Middleware for () { } } +impl> Middleware for &T { + type Output = T::Output; + + fn transform(&self, ep: E) -> Self::Output { + T::transform(self, ep) + } +} + /// A middleware that combines two middlewares. pub struct CombineMiddleware { a: A,