Skip to content

A feature request: implement retain on HeaderMap #632

Open
@bassmanitram

Description

@bassmanitram

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));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions