Skip to content

Commit fef6ad5

Browse files
authored
Rollup merge of rust-lang#140956 - Kixunil:impl-partialeq-str-for-path, r=Amanieu
`impl PartialEq<{str,String}> for {Path,PathBuf}` This is a revival of rust-lang#105877 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
2 parents b4e28fd + 596849d commit fef6ad5

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

std/src/path.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,38 @@ impl PartialEq for PathBuf {
21052105
}
21062106
}
21072107

2108+
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
2109+
impl cmp::PartialEq<str> for PathBuf {
2110+
#[inline]
2111+
fn eq(&self, other: &str) -> bool {
2112+
&*self == other
2113+
}
2114+
}
2115+
2116+
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
2117+
impl cmp::PartialEq<PathBuf> for str {
2118+
#[inline]
2119+
fn eq(&self, other: &PathBuf) -> bool {
2120+
other == self
2121+
}
2122+
}
2123+
2124+
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
2125+
impl cmp::PartialEq<String> for PathBuf {
2126+
#[inline]
2127+
fn eq(&self, other: &String) -> bool {
2128+
**self == **other
2129+
}
2130+
}
2131+
2132+
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
2133+
impl cmp::PartialEq<PathBuf> for String {
2134+
#[inline]
2135+
fn eq(&self, other: &PathBuf) -> bool {
2136+
other == self
2137+
}
2138+
}
2139+
21082140
#[stable(feature = "rust1", since = "1.0.0")]
21092141
impl Hash for PathBuf {
21102142
fn hash<H: Hasher>(&self, h: &mut H) {
@@ -3366,6 +3398,39 @@ impl PartialEq for Path {
33663398
}
33673399
}
33683400

3401+
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
3402+
impl cmp::PartialEq<str> for Path {
3403+
#[inline]
3404+
fn eq(&self, other: &str) -> bool {
3405+
let other: &OsStr = other.as_ref();
3406+
self == other
3407+
}
3408+
}
3409+
3410+
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
3411+
impl cmp::PartialEq<Path> for str {
3412+
#[inline]
3413+
fn eq(&self, other: &Path) -> bool {
3414+
other == self
3415+
}
3416+
}
3417+
3418+
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
3419+
impl cmp::PartialEq<String> for Path {
3420+
#[inline]
3421+
fn eq(&self, other: &String) -> bool {
3422+
self == &*other
3423+
}
3424+
}
3425+
3426+
#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
3427+
impl cmp::PartialEq<Path> for String {
3428+
#[inline]
3429+
fn eq(&self, other: &Path) -> bool {
3430+
other == self
3431+
}
3432+
}
3433+
33693434
#[stable(feature = "rust1", since = "1.0.0")]
33703435
impl Hash for Path {
33713436
fn hash<H: Hasher>(&self, h: &mut H) {

0 commit comments

Comments
 (0)