Skip to content

Commit 0adcb50

Browse files
author
Stjepan Glavina
committed
Add ToOwned and Borrow impls
1 parent ba87048 commit 0adcb50

File tree

7 files changed

+19
-5
lines changed

7 files changed

+19
-5
lines changed

src/fs/canonicalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::task::blocking;
3232
/// # Ok(()) }) }
3333
/// ```
3434
pub async fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
35-
let path: std::path::PathBuf = path.as_ref().to_path_buf().into();
35+
let path: PathBuf = path.as_ref().to_owned();
3636
Ok(blocking::spawn(async move { std::fs::canonicalize(&path) })
3737
.await?
3838
.into())

src/fs/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::task::blocking;
3535
/// # Ok(()) }) }
3636
/// ```
3737
pub async fn metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
38-
let path: std::path::PathBuf = path.as_ref().to_path_buf().into();
38+
let path = path.as_ref().to_owned();
3939
blocking::spawn(async move { std::fs::metadata(path) }).await
4040
}
4141

src/fs/read_dir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use crate::task::{blocking, Context, JoinHandle, Poll};
4444
/// # Ok(()) }) }
4545
/// ```
4646
pub async fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
47-
let path: std::path::PathBuf = path.as_ref().to_path_buf().into();
47+
let path = path.as_ref().to_owned();
4848
blocking::spawn(async move { std::fs::read_dir(path) })
4949
.await
5050
.map(ReadDir::new)

src/fs/read_link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::task::blocking;
2727
/// # Ok(()) }) }
2828
/// ```
2929
pub async fn read_link<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
30-
let path: std::path::PathBuf = path.as_ref().to_path_buf().into();
30+
let path = path.as_ref().to_owned();
3131
Ok(blocking::spawn(async move { std::fs::read_link(path) })
3232
.await?
3333
.into())

src/fs/symlink_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ use crate::task::blocking;
3333
/// # Ok(()) }) }
3434
/// ```
3535
pub async fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
36-
let path: std::path::PathBuf = path.as_ref().to_path_buf().into();
36+
let path = path.as_ref().to_owned();
3737
blocking::spawn(async move { std::fs::symlink_metadata(path) }).await
3838
}

src/path/path.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,11 @@ impl AsRef<Path> for String {
830830
Path::new(self)
831831
}
832832
}
833+
834+
impl std::borrow::ToOwned for Path {
835+
type Owned = PathBuf;
836+
837+
fn to_owned(&self) -> PathBuf {
838+
self.to_path_buf()
839+
}
840+
}

src/path/pathbuf.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ impl std::ops::Deref for PathBuf {
192192
}
193193
}
194194

195+
impl std::borrow::Borrow<Path> for PathBuf {
196+
fn borrow(&self) -> &Path {
197+
&**self
198+
}
199+
}
200+
195201
impl From<std::path::PathBuf> for PathBuf {
196202
fn from(path: std::path::PathBuf) -> PathBuf {
197203
PathBuf { inner: path }

0 commit comments

Comments
 (0)