Skip to content

Rework char::eq_ignore_ascii_case parameter type #57227

Open
@czipperz

Description

@czipperz

Right now:

pub fn eq_ignore_ascii_case(&self, other: &char) -> bool {
    self.to_ascii_lowercase() == other.to_ascii_lowercase()
}

This means that 'a'.eq_ignore_ascii_case('b') doesn't compile. Instead the user must type 'a'.eq_ignore_ascii_case(&'b'). I would like to allow for both without breaking backwards compatibility.

One option would be to change the signature to the following:

pub fn eq_ignore_ascii_case<C: AsRef<char>>(&self, other: C) -> bool {
    self.to_ascii_lowercase() == other.as_ref().to_ascii_lowercase()
}

This would require us to implement AsRef<char> for char and &char to facilitate this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-strArea: str and StringC-enhancementCategory: An issue proposing an enhancement or a PR with one.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