ACP: Implement PartialEq<str> for Path, PathBuf and vice-versa · Issue #151 · rust-lang/libs-team (original) (raw)

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 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.

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.