Skip to content

Commit 409bffa

Browse files
committed
Add mutual PartialEq and PartialOrd impls for Path[Buf] and OsStr[ing]
1 parent ccad544 commit 409bffa

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/libstd/path.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,53 @@ impl_cmp!(Cow<'a, Path>, Path);
20892089
impl_cmp!(Cow<'a, Path>, &'b Path);
20902090
impl_cmp!(Cow<'a, Path>, PathBuf);
20912091

2092+
macro_rules! impl_cmp_os_str {
2093+
($lhs:ty, $rhs: ty) => {
2094+
#[stable(feature = "cmp_path", since = "1.8.0")]
2095+
impl<'a, 'b> PartialEq<$rhs> for $lhs {
2096+
#[inline]
2097+
fn eq(&self, other: &$rhs) -> bool { <Path as PartialEq>::eq(self, other.as_ref()) }
2098+
}
2099+
2100+
#[stable(feature = "cmp_path", since = "1.8.0")]
2101+
impl<'a, 'b> PartialEq<$lhs> for $rhs {
2102+
#[inline]
2103+
fn eq(&self, other: &$lhs) -> bool { <Path as PartialEq>::eq(self.as_ref(), other) }
2104+
}
2105+
2106+
#[stable(feature = "cmp_path", since = "1.8.0")]
2107+
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
2108+
#[inline]
2109+
fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> {
2110+
<Path as PartialOrd>::partial_cmp(self, other.as_ref())
2111+
}
2112+
}
2113+
2114+
#[stable(feature = "cmp_path", since = "1.8.0")]
2115+
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
2116+
#[inline]
2117+
fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> {
2118+
<Path as PartialOrd>::partial_cmp(self.as_ref(), other)
2119+
}
2120+
}
2121+
}
2122+
}
2123+
2124+
impl_cmp_os_str!(PathBuf, OsStr);
2125+
impl_cmp_os_str!(PathBuf, &'a OsStr);
2126+
impl_cmp_os_str!(PathBuf, Cow<'a, OsStr>);
2127+
impl_cmp_os_str!(PathBuf, OsString);
2128+
impl_cmp_os_str!(Path, OsStr);
2129+
impl_cmp_os_str!(Path, &'a OsStr);
2130+
impl_cmp_os_str!(Path, Cow<'a, OsStr>);
2131+
impl_cmp_os_str!(Path, OsString);
2132+
impl_cmp_os_str!(&'a Path, OsStr);
2133+
impl_cmp_os_str!(&'a Path, Cow<'b, OsStr>);
2134+
impl_cmp_os_str!(&'a Path, OsString);
2135+
impl_cmp_os_str!(Cow<'a, Path>, OsStr);
2136+
impl_cmp_os_str!(Cow<'a, Path>, &'b OsStr);
2137+
impl_cmp_os_str!(Cow<'a, Path>, OsString);
2138+
20922139
#[stable(since = "1.7.0", feature = "strip_prefix")]
20932140
impl fmt::Display for StripPrefixError {
20942141
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

0 commit comments

Comments
 (0)