impl IntoCow for Path[Buf]
This commit is contained in:
parent
880fb89bde
commit
2de7a7c9ba
1 changed files with 33 additions and 1 deletions
|
@ -108,7 +108,7 @@
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
|
|
||||||
use ascii::*;
|
use ascii::*;
|
||||||
use borrow::{Borrow, ToOwned, Cow};
|
use borrow::{Borrow, IntoCow, ToOwned, Cow};
|
||||||
use cmp;
|
use cmp;
|
||||||
use iter::{self, IntoIterator};
|
use iter::{self, IntoIterator};
|
||||||
use mem;
|
use mem;
|
||||||
|
@ -987,6 +987,18 @@ impl Borrow<Path> for PathBuf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoCow<'static, Path> for PathBuf {
|
||||||
|
fn into_cow(self) -> Cow<'static, Path> {
|
||||||
|
Cow::Owned(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> IntoCow<'a, Path> for &'a Path {
|
||||||
|
fn into_cow(self) -> Cow<'a, Path> {
|
||||||
|
Cow::Borrowed(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ToOwned for Path {
|
impl ToOwned for Path {
|
||||||
type Owned = PathBuf;
|
type Owned = PathBuf;
|
||||||
fn to_owned(&self) -> PathBuf { self.to_path_buf() }
|
fn to_owned(&self) -> PathBuf { self.to_path_buf() }
|
||||||
|
@ -1411,6 +1423,26 @@ mod tests {
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn into_cow() {
|
||||||
|
use borrow::{Cow, IntoCow};
|
||||||
|
|
||||||
|
let static_path = Path::new("/home/foo");
|
||||||
|
let static_cow_path: Cow<'static, Path> = static_path.into_cow();
|
||||||
|
let pathbuf = PathBuf::new("/home/foo");
|
||||||
|
|
||||||
|
{
|
||||||
|
let path: &Path = &pathbuf;
|
||||||
|
let borrowed_cow_path: Cow<Path> = path.into_cow();
|
||||||
|
|
||||||
|
assert_eq!(static_cow_path, borrowed_cow_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let owned_cow_path: Cow<'static, Path> = pathbuf.into_cow();
|
||||||
|
|
||||||
|
assert_eq!(static_cow_path, owned_cow_path);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub fn test_decompositions_unix() {
|
pub fn test_decompositions_unix() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue