diff options
| author | Kevin Butler <haqkrs@gmail.com> | 2015-11-03 04:51:21 +0000 |
|---|---|---|
| committer | Kevin Butler <haqkrs@gmail.com> | 2015-11-03 17:41:42 +0000 |
| commit | cc830ef18b3014158715f0fd5635a179c5bd7844 (patch) | |
| tree | d7339841ef867d500b90429a89c4345906e9b2c0 | |
| parent | 7690ec89ffeac4b4537e71c980d65ead9177d76c (diff) | |
| download | rust-cc830ef18b3014158715f0fd5635a179c5bd7844.tar.gz rust-cc830ef18b3014158715f0fd5635a179c5bd7844.zip | |
libstd: implement PartialEq<Path> for PathBuf and Cow<Path>
| -rw-r--r-- | src/libstd/path.rs | 48 |
1 files changed, 48 insertions, 0 deletions
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 { <Path as PartialEq>::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 { <Path as PartialEq>::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::*; @@ -3107,6 +3130,31 @@ mod tests { } #[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<Path> = borrowed.into(); + let owned_cow: Cow<Path> = 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}; |
