Skip to content

slice::contains with borrowed data #62367

Open
@RalfJung

Description

@RalfJung

HashSet::contains has the following type to allow e.g. searching in a HashSet<String> with an &str:

pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool where
    T: Borrow<Q>,
    Q: Hash + Eq, 

However, slice::contains does not use Borrow, so to search in an &[String] one has to actually allocate a String:

pub fn contains(&self, x: &T) -> bool where
    T: PartialEq<T>, 

Is there a fundamental reason for this, or is this just an omission?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions