Skip to content

Commit

Permalink
Implement middleware for &T: Middleware<_>
Browse files Browse the repository at this point in the history
That allows to pass middlewares with their configuration around at
application setup time without having to clone them.
  • Loading branch information
horazont committed Dec 22, 2024
1 parent 1350956 commit 4a73190
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions poem/src/middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ impl<E: Endpoint> Middleware<E> for () {
}
}

impl<E: Endpoint, T: Middleware<E>> Middleware<E> 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, B, E> {
a: A,
Expand Down

0 comments on commit 4a73190

Please sign in to comment.