|
108 | 108 | use core::prelude::*;
|
109 | 109 |
|
110 | 110 | use ascii::*;
|
111 |
| -use borrow::{Borrow, ToOwned, Cow}; |
| 111 | +use borrow::{Borrow, IntoCow, ToOwned, Cow}; |
112 | 112 | use cmp;
|
113 | 113 | use iter::{self, IntoIterator};
|
114 | 114 | use mem;
|
@@ -987,6 +987,18 @@ impl Borrow<Path> for PathBuf {
|
987 | 987 | }
|
988 | 988 | }
|
989 | 989 |
|
| 990 | +impl IntoCow<'static, Path> for PathBuf { |
| 991 | + fn into_cow(self) -> Cow<'static, Path> { |
| 992 | + Cow::Owned(self) |
| 993 | + } |
| 994 | +} |
| 995 | + |
| 996 | +impl<'a> IntoCow<'a, Path> for &'a Path { |
| 997 | + fn into_cow(self) -> Cow<'a, Path> { |
| 998 | + Cow::Borrowed(self) |
| 999 | + } |
| 1000 | +} |
| 1001 | + |
990 | 1002 | impl ToOwned for Path {
|
991 | 1003 | type Owned = PathBuf;
|
992 | 1004 | fn to_owned(&self) -> PathBuf { self.to_path_buf() }
|
@@ -1411,6 +1423,26 @@ mod tests {
|
1411 | 1423 | );
|
1412 | 1424 | );
|
1413 | 1425 |
|
| 1426 | + #[test] |
| 1427 | + fn into_cow() { |
| 1428 | + use borrow::{Cow, IntoCow}; |
| 1429 | + |
| 1430 | + let static_path = Path::new("/home/foo"); |
| 1431 | + let static_cow_path: Cow<'static, Path> = static_path.into_cow(); |
| 1432 | + let pathbuf = PathBuf::new("/home/foo"); |
| 1433 | + |
| 1434 | + { |
| 1435 | + let path: &Path = &pathbuf; |
| 1436 | + let borrowed_cow_path: Cow<Path> = path.into_cow(); |
| 1437 | + |
| 1438 | + assert_eq!(static_cow_path, borrowed_cow_path); |
| 1439 | + } |
| 1440 | + |
| 1441 | + let owned_cow_path: Cow<'static, Path> = pathbuf.into_cow(); |
| 1442 | + |
| 1443 | + assert_eq!(static_cow_path, owned_cow_path); |
| 1444 | + } |
| 1445 | + |
1414 | 1446 | #[test]
|
1415 | 1447 | #[cfg(unix)]
|
1416 | 1448 | pub fn test_decompositions_unix() {
|
|
0 commit comments