diff --git a/src/fs/copy.rs b/src/fs/copy.rs index fc3fd3e6..c0c6b9e9 100644 --- a/src/fs/copy.rs +++ b/src/fs/copy.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Copies the contents and permissions of a file to a new location. diff --git a/src/fs/create_dir.rs b/src/fs/create_dir.rs index aa2d5724..99f4ac45 100644 --- a/src/fs/create_dir.rs +++ b/src/fs/create_dir.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Creates a new directory. diff --git a/src/fs/create_dir_all.rs b/src/fs/create_dir_all.rs index 33176f75..0dc446e1 100644 --- a/src/fs/create_dir_all.rs +++ b/src/fs/create_dir_all.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Creates a new directory and all of its parents if they are missing. diff --git a/src/fs/dir_builder.rs b/src/fs/dir_builder.rs index 3064f7a3..1fb08502 100644 --- a/src/fs/dir_builder.rs +++ b/src/fs/dir_builder.rs @@ -1,9 +1,8 @@ -use std::path::Path; - use cfg_if::cfg_if; use crate::future::Future; use crate::io; +use crate::path::Path; use crate::task::blocking; /// A builder for creating directories with configurable options. diff --git a/src/fs/dir_entry.rs b/src/fs/dir_entry.rs index 66b3cb7c..3d42f83b 100644 --- a/src/fs/dir_entry.rs +++ b/src/fs/dir_entry.rs @@ -1,12 +1,12 @@ use std::ffi::OsString; use std::fmt; -use std::path::PathBuf; use std::sync::Arc; use cfg_if::cfg_if; use crate::fs::{FileType, Metadata}; use crate::io; +use crate::path::PathBuf; use crate::task::blocking; /// An entry in a directory. @@ -50,7 +50,7 @@ impl DirEntry { /// # Ok(()) }) } /// ``` pub fn path(&self) -> PathBuf { - self.0.path() + self.0.path().into() } /// Reads the metadata for this entry. diff --git a/src/fs/file.rs b/src/fs/file.rs index bdf93474..b52bcd07 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -3,7 +3,6 @@ use std::cmp; use std::fmt; use std::io::{Read as _, Seek as _, Write as _}; use std::ops::{Deref, DerefMut}; -use std::path::Path; use std::pin::Pin; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; @@ -13,6 +12,7 @@ use cfg_if::cfg_if; use crate::fs::{Metadata, Permissions}; use crate::future; use crate::io::{self, Read, Seek, SeekFrom, Write}; +use crate::path::Path; use crate::prelude::*; use crate::task::{self, blocking, Context, Poll, Waker}; diff --git a/src/fs/hard_link.rs b/src/fs/hard_link.rs index 5f950cde..2ae2cad4 100644 --- a/src/fs/hard_link.rs +++ b/src/fs/hard_link.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Creates a hard link on the filesystem. diff --git a/src/fs/open_options.rs b/src/fs/open_options.rs index 252873cd..d7e0454f 100644 --- a/src/fs/open_options.rs +++ b/src/fs/open_options.rs @@ -1,10 +1,9 @@ -use std::path::Path; - use cfg_if::cfg_if; use crate::fs::File; use crate::future::Future; use crate::io; +use crate::path::Path; use crate::task::blocking; /// A builder for opening files with configurable options. diff --git a/src/fs/read.rs b/src/fs/read.rs index 6b3560db..b562ea3c 100644 --- a/src/fs/read.rs +++ b/src/fs/read.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Reads the entire contents of a file as raw bytes. diff --git a/src/fs/read_to_string.rs b/src/fs/read_to_string.rs index 345f76ef..a4d175fa 100644 --- a/src/fs/read_to_string.rs +++ b/src/fs/read_to_string.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Reads the entire contents of a file as a string. diff --git a/src/fs/remove_dir.rs b/src/fs/remove_dir.rs index a176edc8..f4571246 100644 --- a/src/fs/remove_dir.rs +++ b/src/fs/remove_dir.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Removes an empty directory. diff --git a/src/fs/remove_dir_all.rs b/src/fs/remove_dir_all.rs index 9db0c31f..3b12d264 100644 --- a/src/fs/remove_dir_all.rs +++ b/src/fs/remove_dir_all.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Removes a directory and all of its contents. diff --git a/src/fs/remove_file.rs b/src/fs/remove_file.rs index cc0eeb25..216209fe 100644 --- a/src/fs/remove_file.rs +++ b/src/fs/remove_file.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Removes a file. diff --git a/src/fs/rename.rs b/src/fs/rename.rs index 72cd227f..f517a266 100644 --- a/src/fs/rename.rs +++ b/src/fs/rename.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Renames a file or directory to a new location. diff --git a/src/fs/set_permissions.rs b/src/fs/set_permissions.rs index 6fa6306f..68dd8d40 100644 --- a/src/fs/set_permissions.rs +++ b/src/fs/set_permissions.rs @@ -1,7 +1,6 @@ -use std::path::Path; - use crate::fs::Permissions; use crate::io; +use crate::path::Path; use crate::task::blocking; /// Changes the permissions of a file or directory. diff --git a/src/fs/write.rs b/src/fs/write.rs index b0d7abcc..4db52212 100644 --- a/src/fs/write.rs +++ b/src/fs/write.rs @@ -1,6 +1,5 @@ -use std::path::Path; - use crate::io; +use crate::path::Path; use crate::task::blocking; /// Writes a slice of bytes as the new contents of a file. diff --git a/src/os/unix/fs.rs b/src/os/unix/fs.rs index be8932c0..f00aaec6 100644 --- a/src/os/unix/fs.rs +++ b/src/os/unix/fs.rs @@ -1,10 +1,9 @@ //! Unix-specific filesystem extensions. -use std::path::Path; - use cfg_if::cfg_if; use crate::io; +use crate::path::Path; use crate::task::blocking; /// Creates a new symbolic link on the filesystem. diff --git a/src/os/unix/net/datagram.rs b/src/os/unix/net/datagram.rs index 1f971f7f..61adc09e 100644 --- a/src/os/unix/net/datagram.rs +++ b/src/os/unix/net/datagram.rs @@ -2,7 +2,6 @@ use std::fmt; use std::net::Shutdown; -use std::path::Path; use mio_uds; @@ -11,6 +10,7 @@ use crate::future; use crate::io; use crate::net::driver::Watcher; use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +use crate::path::Path; use crate::task::blocking; /// A Unix datagram socket. diff --git a/src/os/unix/net/listener.rs b/src/os/unix/net/listener.rs index eba2fadc..2d68a6b9 100644 --- a/src/os/unix/net/listener.rs +++ b/src/os/unix/net/listener.rs @@ -1,7 +1,6 @@ //! Unix-specific networking extensions. use std::fmt; -use std::path::Path; use std::pin::Pin; use mio_uds; @@ -12,6 +11,7 @@ use crate::future::{self, Future}; use crate::io; use crate::net::driver::Watcher; use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +use crate::path::Path; use crate::stream::Stream; use crate::task::{blocking, Context, Poll}; diff --git a/src/os/unix/net/mod.rs b/src/os/unix/net/mod.rs index a719a484..2c79e8c3 100644 --- a/src/os/unix/net/mod.rs +++ b/src/os/unix/net/mod.rs @@ -13,7 +13,8 @@ mod stream; cfg_if! { if #[cfg(feature = "docs")] { use std::fmt; - use std::path::Path; + + use crate::path::Path; /// An address associated with a Unix socket. /// @@ -65,9 +66,8 @@ cfg_if! { /// With a pathname: /// /// ```no_run - /// use std::path::Path; - /// /// use async_std::os::unix::net::UnixListener; + /// use async_std::path::Path; /// /// let socket = UnixListener::bind("/tmp/socket").await?; /// let addr = socket.local_addr()?; diff --git a/src/os/unix/net/stream.rs b/src/os/unix/net/stream.rs index ae30b5bf..8245e638 100644 --- a/src/os/unix/net/stream.rs +++ b/src/os/unix/net/stream.rs @@ -3,7 +3,6 @@ use std::fmt; use std::io::{Read as _, Write as _}; use std::net::Shutdown; -use std::path::Path; use std::pin::Pin; use mio_uds; @@ -12,6 +11,7 @@ use super::SocketAddr; use crate::io::{self, Read, Write}; use crate::net::driver::Watcher; use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +use crate::path::Path; use crate::task::{blocking, Context, Poll}; /// A Unix stream socket. diff --git a/src/path/path.rs b/src/path/path.rs index 4cb40834..4bc07573 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -801,9 +801,15 @@ impl<'a> Into<&'a std::path::Path> for &'a Path { } } -impl AsRef for Path { - fn as_ref(&self) -> &OsStr { - self.inner.as_ref() +impl AsRef for Path { + fn as_ref(&self) -> &std::path::Path { + self.into() + } +} + +impl AsRef for std::path::Path { + fn as_ref(&self) -> &Path { + self.into() } } @@ -813,6 +819,12 @@ impl AsRef for Path { } } +impl AsRef for Path { + fn as_ref(&self) -> &OsStr { + self.inner.as_ref() + } +} + impl AsRef for OsStr { fn as_ref(&self) -> &Path { Path::new(self)