mirror of
https://github.com/tower-rs/tower.git
synced 2025-09-28 13:30:43 +00:00
ready-cache: Allow iteration over ready services (#700)
Adds `iter_ready` and `iter_ready_mut` to allow iteration over ready services within the ready_cache. This allows the ready cache to be used for router-like services that wish to direct requests towards specific services. Allowing iteration directly means that cache keys do not have to be redundantly stored separate to the ready_cache.
This commit is contained in:
parent
87fa8ef782
commit
7d829f198e
@ -197,6 +197,16 @@ where
|
||||
self.ready.get_index_mut(idx).map(|(k, v)| (k, &mut v.0))
|
||||
}
|
||||
|
||||
/// Returns an iterator over the ready keys and services.
|
||||
pub fn iter_ready(&self) -> impl Iterator<Item = (&K, &S)> {
|
||||
self.ready.iter().map(|(k, s)| (k, &s.0))
|
||||
}
|
||||
|
||||
/// Returns a mutable iterator over the ready keys and services.
|
||||
pub fn iter_ready_mut(&mut self) -> impl Iterator<Item = (&K, &mut S)> {
|
||||
self.ready.iter_mut().map(|(k, s)| (k, &mut s.0))
|
||||
}
|
||||
|
||||
/// Evicts an item from the cache.
|
||||
///
|
||||
/// Returns true if a service was marked for eviction.
|
||||
|
Loading…
x
Reference in New Issue
Block a user