mirror of
https://github.com/tower-rs/tower.git
synced 2025-10-02 15:25:11 +00:00
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:
parent
7aecf78ac0
commit
b4169c7753
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user