Skip to content

Can we have an API similar to HashMap::retain? #62

@linrongbin16

Description

@linrongbin16

Hi, can we have an API similar to HashMap::retain:

pub fn retain<F>(&mut self, f: F)
where
    F: FnMut(&K, &mut V) -> bool

It only retains all the elements that satisfies the f predicate, and removes all other elements?

Actually I don't mind to use the drain API to archive the same result, I think I could first use drain to empty the cache, and iterate all the elements and insert back those satisfy the f predicate.

Do they have the same performance?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions