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

ACP: Implement PartialEq<str> for Path, PathBuf and vice-versa #151

Closed
Kixunil opened this issue Dec 18, 2022 · 1 comment
Closed

ACP: Implement PartialEq<str> for Path, PathBuf and vice-versa #151

Kixunil opened this issue Dec 18, 2022 · 1 comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api

Comments

@Kixunil
Copy link

Kixunil commented Dec 18, 2022

Proposal

Problem statement

When testing functions that return PathBuf one might want to use assert_eq! with a string literal in tests. This is currently impossible because of lacking impls.

Motivation, use-cases

For my use case, the function in question processes program arguments assuming zeroth argument is the path to the program, so it returns PathBuf which should be the most appropriate. In the test I mock the arguments providing a different iterator with known zeroth argument. I wish to compare them to ensure the function returns the correct value.

I would be surprised if there weren't any other tested existing crates that do some path computation.

Solution sketches

impl PartialEq<str> for Path {
    fn eq(&self, other: &str) -> bool {
        let other: &Path = other.as_ref();
        self == other
    }
}

// other impls can call into the one above

I believe this is the obvious, idiomatic solution. I don't see any meaningful downsides.

Links and related work

N/A, will send a PR if this is approved.

What happens now?

This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.

@Kixunil Kixunil added api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api labels Dec 18, 2022
@dtolnay
Copy link
Member

dtolnay commented Dec 18, 2022

Seconded, please send a PR.

Kixunil added a commit to Kixunil/rust that referenced this issue Jan 2, 2023
Comparison of paths and strings is expected to be possible and needed
e.g. in tests. This change adds the impls os `PartialEq` between strings
and paths, both owned and unsized, in both directions.

ACP: rust-lang/libs-team#151
@dtolnay dtolnay added the ACP-accepted API Change Proposal is accepted (seconded with no objections) label May 30, 2023
@dtolnay dtolnay closed this as completed May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api
Projects
None yet
Development

No branches or pull requests

2 participants