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:
Sam Lewis 2022-10-18 04:19:26 +11:00 committed by GitHub
parent 87fa8ef782
commit 7d829f198e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.