Skip to content

Missing PartialEq<&str> impls on Path and PathBuf #71700

Open
@lopopolo

Description

Given that &OsStr is comparable to &str, I would expect &Path (and PathBuf) to be comparable to &str since &OsStr and &Path can freely convert to each other.

Example

use std::path::{Path, PathBuf};

fn main() {
    let path = PathBuf::from("-");
    println!("{}", path == Path::new("-"));
    println!("{}", path.as_os_str() == Path::new("-"));
    println!("{}", path.as_os_str() == "-");
    println!("{}", path == "-");
    let path = Path::new("-");
    println!("{}", path == PathBuf::from("-"));
    println!("{}", path.as_os_str() == Path::new("-"));
    println!("{}", path.as_os_str() == "-");
    println!("{}", path == "-");
}

Playground

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=acfe18e120c54faf105d655c12a86ea7

Metadata

Assignees

No one assigned

    Labels

    A-strArea: str and StringC-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