about summary refs log tree commit diff
path: root/library/std/src/path.rs
diff options
context:
space:
mode:
authorMartin Habovstiak <martin.habovstiak@gmail.com>2022-12-18 19:36:39 +0100
committerMartin Habovstiak <martin.habovstiak@gmail.com>2025-05-13 23:41:18 +0200
commitaab1563d42ed7cf54b017ad414f95fa45526f566 (patch)
tree88bc8c40df4dc0e4d332d945cf3b5f5765c35846 /library/std/src/path.rs
parent8405332bdf09b153e475f83b8b8ebf8d4e8eb81f (diff)
downloadrust-aab1563d42ed7cf54b017ad414f95fa45526f566.tar.gz
rust-aab1563d42ed7cf54b017ad414f95fa45526f566.zip
`impl PartialEq<{str,String}> for {Path,PathBuf}`
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: https://github.com/rust-lang/libs-team/issues/151
Diffstat (limited to 'library/std/src/path.rs')
-rw-r--r--library/std/src/path.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs
index 1a4a7aa7448..30b12a0e796 100644
--- a/library/std/src/path.rs
+++ b/library/std/src/path.rs
@@ -2068,6 +2068,38 @@ impl PartialEq for PathBuf {
     }
 }
 
+#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
+impl cmp::PartialEq<str> for PathBuf {
+    #[inline]
+    fn eq(&self, other: &str) -> bool {
+        &*self == other
+    }
+}
+
+#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
+impl cmp::PartialEq<PathBuf> for str {
+    #[inline]
+    fn eq(&self, other: &PathBuf) -> bool {
+        other == self
+    }
+}
+
+#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
+impl cmp::PartialEq<String> for PathBuf {
+    #[inline]
+    fn eq(&self, other: &String) -> bool {
+        **self == **other
+    }
+}
+
+#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
+impl cmp::PartialEq<PathBuf> for String {
+    #[inline]
+    fn eq(&self, other: &PathBuf) -> bool {
+        other == self
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl Hash for PathBuf {
     fn hash<H: Hasher>(&self, h: &mut H) {
@@ -3242,6 +3274,39 @@ impl PartialEq for Path {
     }
 }
 
+#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
+impl cmp::PartialEq<str> for Path {
+    #[inline]
+    fn eq(&self, other: &str) -> bool {
+        let other: &OsStr = other.as_ref();
+        self == other
+    }
+}
+
+#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
+impl cmp::PartialEq<Path> for str {
+    #[inline]
+    fn eq(&self, other: &Path) -> bool {
+        other == self
+    }
+}
+
+#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
+impl cmp::PartialEq<String> for Path {
+    #[inline]
+    fn eq(&self, other: &String) -> bool {
+        self == &*other
+    }
+}
+
+#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
+impl cmp::PartialEq<Path> for String {
+    #[inline]
+    fn eq(&self, other: &Path) -> bool {
+        other == self
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl Hash for Path {
     fn hash<H: Hasher>(&self, h: &mut H) {