mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Auto merge of #29532 - Ryman:cow_path, r=alexcrichton
This commit is contained in:
commit
2a7bd082ac
@ -963,7 +963,7 @@ impl PartialEq for String {
|
||||
macro_rules! impl_eq {
|
||||
($lhs:ty, $rhs: ty) => {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a> PartialEq<$rhs> for $lhs {
|
||||
impl<'a, 'b> PartialEq<$rhs> for $lhs {
|
||||
#[inline]
|
||||
fn eq(&self, other: &$rhs) -> bool { PartialEq::eq(&self[..], &other[..]) }
|
||||
#[inline]
|
||||
@ -971,7 +971,7 @@ macro_rules! impl_eq {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a> PartialEq<$lhs> for $rhs {
|
||||
impl<'a, 'b> PartialEq<$lhs> for $rhs {
|
||||
#[inline]
|
||||
fn eq(&self, other: &$lhs) -> bool { PartialEq::eq(&self[..], &other[..]) }
|
||||
#[inline]
|
||||
@ -984,24 +984,9 @@ macro_rules! impl_eq {
|
||||
impl_eq! { String, str }
|
||||
impl_eq! { String, &'a str }
|
||||
impl_eq! { Cow<'a, str>, str }
|
||||
impl_eq! { Cow<'a, str>, &'b str }
|
||||
impl_eq! { Cow<'a, str>, String }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, 'b> PartialEq<&'b str> for Cow<'a, str> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &&'b str) -> bool { PartialEq::eq(&self[..], &other[..]) }
|
||||
#[inline]
|
||||
fn ne(&self, other: &&'b str) -> bool { PartialEq::ne(&self[..], &other[..]) }
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, 'b> PartialEq<Cow<'a, str>> for &'b str {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Cow<'a, str>) -> bool { PartialEq::eq(&self[..], &other[..]) }
|
||||
#[inline]
|
||||
fn ne(&self, other: &Cow<'a, str>) -> bool { PartialEq::ne(&self[..], &other[..]) }
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Default for String {
|
||||
#[inline]
|
||||
|
@ -1166,6 +1166,22 @@ impl<'a> IntoCow<'a, Path> for &'a Path {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "cow_from_path", since = "1.6.0")]
|
||||
impl<'a> From<&'a Path> for Cow<'a, Path> {
|
||||
#[inline]
|
||||
fn from(s: &'a Path) -> Cow<'a, Path> {
|
||||
Cow::Borrowed(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "cow_from_path", since = "1.6.0")]
|
||||
impl<'a> From<PathBuf> for Cow<'a, Path> {
|
||||
#[inline]
|
||||
fn from(s: PathBuf) -> Cow<'a, Path> {
|
||||
Cow::Owned(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl ToOwned for Path {
|
||||
type Owned = PathBuf;
|
||||
@ -1893,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::*;
|
||||
@ -2002,6 +2041,26 @@ mod tests {
|
||||
assert_eq!(static_cow_path, owned_cow_path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into() {
|
||||
use borrow::Cow;
|
||||
|
||||
let static_path = Path::new("/home/foo");
|
||||
let static_cow_path: Cow<'static, Path> = static_path.into();
|
||||
let pathbuf = PathBuf::from("/home/foo");
|
||||
|
||||
{
|
||||
let path: &Path = &pathbuf;
|
||||
let borrowed_cow_path: Cow<Path> = path.into();
|
||||
|
||||
assert_eq!(static_cow_path, borrowed_cow_path);
|
||||
}
|
||||
|
||||
let owned_cow_path: Cow<'static, Path> = pathbuf.into();
|
||||
|
||||
assert_eq!(static_cow_path, owned_cow_path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
pub fn test_decompositions_unix() {
|
||||
@ -3070,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<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};
|
||||
|
Loading…
Reference in New Issue
Block a user