@@ -1166,6 +1166,22 @@ impl<'a> IntoCow<'a, Path> for &'a Path {
11661166 }
11671167}
11681168
1169+ #[ stable( feature = "cow_from_path" , since = "1.6.0" ) ]
1170+ impl < ' a > From < & ' a Path > for Cow < ' a , Path > {
1171+ #[ inline]
1172+ fn from ( s : & ' a Path ) -> Cow < ' a , Path > {
1173+ Cow :: Borrowed ( s)
1174+ }
1175+ }
1176+
1177+ #[ stable( feature = "cow_from_path" , since = "1.6.0" ) ]
1178+ impl < ' a > From < PathBuf > for Cow < ' a , Path > {
1179+ #[ inline]
1180+ fn from ( s : PathBuf ) -> Cow < ' a , Path > {
1181+ Cow :: Owned ( s)
1182+ }
1183+ }
1184+
11691185#[ stable( feature = "rust1" , since = "1.0.0" ) ]
11701186impl ToOwned for Path {
11711187 type Owned = PathBuf ;
@@ -1893,6 +1909,29 @@ impl<'a> IntoIterator for &'a Path {
18931909 fn into_iter ( self ) -> Iter < ' a > { self . iter ( ) }
18941910}
18951911
1912+ macro_rules! impl_eq {
1913+ ( $lhs: ty, $rhs: ty) => {
1914+ #[ stable( feature = "partialeq_path" , since = "1.6.0" ) ]
1915+ impl <' a, ' b> PartialEq <$rhs> for $lhs {
1916+ #[ inline]
1917+ fn eq( & self , other: & $rhs) -> bool { <Path as PartialEq >:: eq( self , other) }
1918+ }
1919+
1920+ #[ stable( feature = "partialeq_path" , since = "1.6.0" ) ]
1921+ impl <' a, ' b> PartialEq <$lhs> for $rhs {
1922+ #[ inline]
1923+ fn eq( & self , other: & $lhs) -> bool { <Path as PartialEq >:: eq( self , other) }
1924+ }
1925+
1926+ }
1927+ }
1928+
1929+ impl_eq ! ( PathBuf , Path ) ;
1930+ impl_eq ! ( PathBuf , & ' a Path ) ;
1931+ impl_eq ! ( Cow <' a, Path >, Path ) ;
1932+ impl_eq ! ( Cow <' a, Path >, & ' b Path ) ;
1933+ impl_eq ! ( Cow <' a, Path >, PathBuf ) ;
1934+
18961935#[ cfg( test) ]
18971936mod tests {
18981937 use super :: * ;
@@ -2002,6 +2041,26 @@ mod tests {
20022041 assert_eq ! ( static_cow_path, owned_cow_path) ;
20032042 }
20042043
2044+ #[ test]
2045+ fn into ( ) {
2046+ use borrow:: Cow ;
2047+
2048+ let static_path = Path :: new ( "/home/foo" ) ;
2049+ let static_cow_path: Cow < ' static , Path > = static_path. into ( ) ;
2050+ let pathbuf = PathBuf :: from ( "/home/foo" ) ;
2051+
2052+ {
2053+ let path: & Path = & pathbuf;
2054+ let borrowed_cow_path: Cow < Path > = path. into ( ) ;
2055+
2056+ assert_eq ! ( static_cow_path, borrowed_cow_path) ;
2057+ }
2058+
2059+ let owned_cow_path: Cow < ' static , Path > = pathbuf. into ( ) ;
2060+
2061+ assert_eq ! ( static_cow_path, owned_cow_path) ;
2062+ }
2063+
20052064 #[ test]
20062065 #[ cfg( unix) ]
20072066 pub fn test_decompositions_unix ( ) {
@@ -3070,6 +3129,31 @@ mod tests {
30703129 tfe ! ( "/" , "foo" , "/" , false ) ;
30713130 }
30723131
3132+ #[ test]
3133+ fn test_eq_recievers ( ) {
3134+ use borrow:: Cow ;
3135+
3136+ let borrowed: & Path = Path :: new ( "foo/bar" ) ;
3137+ let mut owned: PathBuf = PathBuf :: new ( ) ;
3138+ owned. push ( "foo" ) ;
3139+ owned. push ( "bar" ) ;
3140+ let borrowed_cow: Cow < Path > = borrowed. into ( ) ;
3141+ let owned_cow: Cow < Path > = owned. clone ( ) . into ( ) ;
3142+
3143+ macro_rules! t {
3144+ ( $( $current: expr) ,+) => {
3145+ $(
3146+ assert_eq!( $current, borrowed) ;
3147+ assert_eq!( $current, owned) ;
3148+ assert_eq!( $current, borrowed_cow) ;
3149+ assert_eq!( $current, owned_cow) ;
3150+ ) +
3151+ }
3152+ }
3153+
3154+ t ! ( borrowed, owned, borrowed_cow, owned_cow) ;
3155+ }
3156+
30733157 #[ test]
30743158 pub fn test_compare ( ) {
30753159 use hash:: { Hash , Hasher , SipHasher } ;
0 commit comments