@@ -1166,6 +1166,22 @@ impl<'a> IntoCow<'a, Path> for &'a Path {
1166
1166
}
1167
1167
}
1168
1168
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
+
1169
1185
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1170
1186
impl ToOwned for Path {
1171
1187
type Owned = PathBuf ;
@@ -1893,6 +1909,29 @@ impl<'a> IntoIterator for &'a Path {
1893
1909
fn into_iter ( self ) -> Iter < ' a > { self . iter ( ) }
1894
1910
}
1895
1911
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
+
1896
1935
#[ cfg( test) ]
1897
1936
mod tests {
1898
1937
use super :: * ;
@@ -2002,6 +2041,26 @@ mod tests {
2002
2041
assert_eq ! ( static_cow_path, owned_cow_path) ;
2003
2042
}
2004
2043
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
+
2005
2064
#[ test]
2006
2065
#[ cfg( unix) ]
2007
2066
pub fn test_decompositions_unix ( ) {
@@ -3070,6 +3129,31 @@ mod tests {
3070
3129
tfe ! ( "/" , "foo" , "/" , false ) ;
3071
3130
}
3072
3131
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
+
3073
3157
#[ test]
3074
3158
pub fn test_compare ( ) {
3075
3159
use hash:: { Hash , Hasher , SipHasher } ;
0 commit comments