Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A feature request: implement retain on HeaderMap #632

Open
bassmanitram opened this issue Oct 27, 2023 · 0 comments
Open

A feature request: implement retain on HeaderMap #632

bassmanitram opened this issue Oct 27, 2023 · 0 comments

Comments

@bassmanitram
Copy link

It would be really handy to have the retain method available (as per std::collections) in order to allow headers to be removed based upon a closure. This would, for example, avoid the double-scan and "clone key" issues when one has a list of headers that must be retained or removed:

let delete_list: Vec<HeaderName> = headers
            .keys()
            .filter(|k| !allowed_headers.contains(*k))
            .map(|k| k.clone())
            .collect::<Vec<HeaderName>>();
for header in delete_list {
    headers.remove(header);
}

would be replaced with

headers.retain(|(k,v)| allowed_headers.contains(*k));
@bassmanitram bassmanitram changed the title A feature request: implement retain A feature request: implement retain on HeaderMap Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant