@@ -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 ;
@@ -2002,6 +2018,26 @@ mod tests {
2002
2018
assert_eq ! ( static_cow_path, owned_cow_path) ;
2003
2019
}
2004
2020
2021
+ #[ test]
2022
+ fn into ( ) {
2023
+ use borrow:: Cow ;
2024
+
2025
+ let static_path = Path :: new ( "/home/foo" ) ;
2026
+ let static_cow_path: Cow < ' static , Path > = static_path. into ( ) ;
2027
+ let pathbuf = PathBuf :: from ( "/home/foo" ) ;
2028
+
2029
+ {
2030
+ let path: & Path = & pathbuf;
2031
+ let borrowed_cow_path: Cow < Path > = path. into ( ) ;
2032
+
2033
+ assert_eq ! ( static_cow_path, borrowed_cow_path) ;
2034
+ }
2035
+
2036
+ let owned_cow_path: Cow < ' static , Path > = pathbuf. into ( ) ;
2037
+
2038
+ assert_eq ! ( static_cow_path, owned_cow_path) ;
2039
+ }
2040
+
2005
2041
#[ test]
2006
2042
#[ cfg( unix) ]
2007
2043
pub fn test_decompositions_unix ( ) {
0 commit comments