Skip to content

Commit 9fb4fca

Browse files
committed
Add mutual PartialEq and PartialCmp impls for OsStr, OsString
1 parent b54770c commit 9fb4fca

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/libstd/ffi/os_str.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,44 @@ impl Ord for OsStr {
343343
fn cmp(&self, other: &OsStr) -> cmp::Ordering { self.bytes().cmp(other.bytes()) }
344344
}
345345

346+
macro_rules! impl_cmp {
347+
($lhs:ty, $rhs: ty) => {
348+
#[stable(feature = "cmp_os_str", since = "1.8.0")]
349+
impl<'a, 'b> PartialEq<$rhs> for $lhs {
350+
#[inline]
351+
fn eq(&self, other: &$rhs) -> bool { <OsStr as PartialEq>::eq(self, other) }
352+
}
353+
354+
#[stable(feature = "cmp_os_str", since = "1.8.0")]
355+
impl<'a, 'b> PartialEq<$lhs> for $rhs {
356+
#[inline]
357+
fn eq(&self, other: &$lhs) -> bool { <OsStr as PartialEq>::eq(self, other) }
358+
}
359+
360+
#[stable(feature = "cmp_os_str", since = "1.8.0")]
361+
impl<'a, 'b> PartialOrd<$rhs> for $lhs {
362+
#[inline]
363+
fn partial_cmp(&self, other: &$rhs) -> Option<cmp::Ordering> {
364+
<OsStr as PartialOrd>::partial_cmp(self, other)
365+
}
366+
}
367+
368+
#[stable(feature = "cmp_os_str", since = "1.8.0")]
369+
impl<'a, 'b> PartialOrd<$lhs> for $rhs {
370+
#[inline]
371+
fn partial_cmp(&self, other: &$lhs) -> Option<cmp::Ordering> {
372+
<OsStr as PartialOrd>::partial_cmp(self, other)
373+
}
374+
}
375+
}
376+
}
377+
378+
impl_cmp!(OsString, OsStr);
379+
impl_cmp!(OsString, &'a OsStr);
380+
impl_cmp!(Cow<'a, OsStr>, OsStr);
381+
impl_cmp!(Cow<'a, OsStr>, &'b OsStr);
382+
impl_cmp!(Cow<'a, OsStr>, OsString);
383+
346384
#[stable(feature = "rust1", since = "1.0.0")]
347385
impl Hash for OsStr {
348386
#[inline]

0 commit comments

Comments
 (0)