Skip to content

Commit

Permalink
Add find_all method to Store
Browse files Browse the repository at this point in the history
Resolves #1633.

Signed-off-by: Alexander Gil <[email protected]>
  • Loading branch information
pando85 committed Nov 10, 2024
1 parent 9c402a6 commit 9f04a48
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions kube-runtime/src/reflector/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ where
.cloned()
}

/// Retrieve all `clone()` of the entries found by the given predicate
#[must_use]
pub fn find_all<P>(&self, predicate: P) -> Vec<Arc<K>>
where
P: Fn(&K) -> bool,
{
self.store

Check warning on line 266 in kube-runtime/src/reflector/store.rs

View check run for this annotation

Codecov / codecov/patch

kube-runtime/src/reflector/store.rs#L266

Added line #L266 was not covered by tests
.read()
.iter()
.map(|(_, k)| k)
.filter(|k| predicate(k.as_ref()))

Check warning on line 270 in kube-runtime/src/reflector/store.rs

View check run for this annotation

Codecov / codecov/patch

kube-runtime/src/reflector/store.rs#L269-L270

Added lines #L269 - L270 were not covered by tests
.cloned()
.collect()
}

/// Return the number of elements in the store
#[must_use]
pub fn len(&self) -> usize {
Expand Down

0 comments on commit 9f04a48

Please sign in to comment.