filter: add get_ref, get_mut, and into_inner (#522)

This branch adds methods to access the inner service of a `Filter` or an
`AsyncFilter`. These are identical to the similarly-named method
provided by many other middleware services.

Along with the changes in #521, this is also necessary to implement
filtered versions of foreign traits in downstream code. I probably
should've added this in that PR, but I wasn't thinking it through...
This commit is contained in:
Eliza Weisman 2021-01-11 15:19:43 -08:00 committed by GitHub
parent 7aecf78ac0
commit b4169c7753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,6 +80,21 @@ impl<T, U> Filter<T, U> {
{
self.predicate.check(request)
}
/// Get a reference to the inner service
pub fn get_ref(&self) -> &T {
&self.inner
}
/// Get a mutable reference to the inner service
pub fn get_mut(&mut self) -> &mut T {
&mut self.inner
}
/// Consume `self`, returning the inner service
pub fn into_inner(self) -> T {
self.inner
}
}
impl<T, U, Request> Service<Request> for Filter<T, U>
@ -127,6 +142,21 @@ impl<T, U> AsyncFilter<T, U> {
{
self.predicate.check(request).await
}
/// Get a reference to the inner service
pub fn get_ref(&self) -> &T {
&self.inner
}
/// Get a mutable reference to the inner service
pub fn get_mut(&mut self) -> &mut T {
&mut self.inner
}
/// Consume `self`, returning the inner service
pub fn into_inner(self) -> T {
self.inner
}
}
impl<T, U, Request> Service<Request> for AsyncFilter<T, U>