From cc830ef18b3014158715f0fd5635a179c5bd7844 Mon Sep 17 00:00:00 2001 From: Kevin Butler Date: Tue, 3 Nov 2015 04:51:21 +0000 Subject: [PATCH] libstd: implement PartialEq for PathBuf and Cow --- src/libstd/path.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index b3f755a60a5..9a5852663cb 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1909,6 +1909,29 @@ impl<'a> IntoIterator for &'a Path { fn into_iter(self) -> Iter<'a> { self.iter() } } +macro_rules! impl_eq { + ($lhs:ty, $rhs: ty) => { + #[stable(feature = "partialeq_path", since = "1.6.0")] + impl<'a, 'b> PartialEq<$rhs> for $lhs { + #[inline] + fn eq(&self, other: &$rhs) -> bool { ::eq(self, other) } + } + + #[stable(feature = "partialeq_path", since = "1.6.0")] + impl<'a, 'b> PartialEq<$lhs> for $rhs { + #[inline] + fn eq(&self, other: &$lhs) -> bool { ::eq(self, other) } + } + + } +} + +impl_eq!(PathBuf, Path); +impl_eq!(PathBuf, &'a Path); +impl_eq!(Cow<'a, Path>, Path); +impl_eq!(Cow<'a, Path>, &'b Path); +impl_eq!(Cow<'a, Path>, PathBuf); + #[cfg(test)] mod tests { use super::*; @@ -3106,6 +3129,31 @@ mod tests { tfe!("/", "foo", "/", false); } + #[test] + fn test_eq_recievers() { + use borrow::Cow; + + let borrowed: &Path = Path::new("foo/bar"); + let mut owned: PathBuf = PathBuf::new(); + owned.push("foo"); + owned.push("bar"); + let borrowed_cow: Cow = borrowed.into(); + let owned_cow: Cow = owned.clone().into(); + + macro_rules! t { + ($($current:expr),+) => { + $( + assert_eq!($current, borrowed); + assert_eq!($current, owned); + assert_eq!($current, borrowed_cow); + assert_eq!($current, owned_cow); + )+ + } + } + + t!(borrowed, owned, borrowed_cow, owned_cow); + } + #[test] pub fn test_compare() { use hash::{Hash, Hasher, SipHasher};