Fixed various tests

yoshuawuyts-patch-1
Wouter Geraedts 5 years ago
parent e690b55b18
commit 6bbfd039b1

@ -6,6 +6,7 @@ use crate::{fs, io};
/// This struct is an async version of [`std::path::Path`].
///
/// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.Path.html
#[derive(Debug, PartialEq)]
pub struct Path {
inner: std::path::Path,
}
@ -28,10 +29,14 @@ impl Path {
/// # Examples
///
/// ```no_run
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::path::{Path, PathBuf};
///
/// let path = Path::new("/foo/test/../test/bar.rs");
/// assert_eq!(path.canonicalize().unwrap(), PathBuf::from("/foo/test/bar.rs"));
/// assert_eq!(path.canonicalize().await.unwrap(), PathBuf::from("/foo/test/bar.rs"));
/// #
/// # Ok(()) }) }
/// ```
pub async fn canonicalize(&self) -> io::Result<PathBuf> {
fs::canonicalize(self).await
@ -86,8 +91,12 @@ impl Path {
/// # Examples
///
/// ```no_run
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
/// #
/// use async_std::path::Path;
/// assert_eq!(Path::new("does_not_exist.txt").exists(), false);
/// assert_eq!(Path::new("does_not_exist.txt").exists().await, false);
/// #
/// # Ok(()) }) }
/// ```
///
/// # See Also
@ -155,14 +164,26 @@ impl<'a> Into<&'a std::path::Path> for &'a Path {
}
}
impl AsRef<OsStr> for Path {
fn as_ref(&self) -> &OsStr {
self.inner.as_ref()
}
}
impl AsRef<Path> for Path {
fn as_ref(&self) -> &Path {
self
}
}
impl std::fmt::Debug for Path {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.inner, formatter)
impl AsRef<Path> for OsStr {
fn as_ref(&self) -> &Path {
Path::new(self)
}
}
impl AsRef<Path> for str {
fn as_ref(&self) -> &Path {
Path::new(self)
}
}

@ -5,6 +5,7 @@ use crate::path::Path;
/// This struct is an async version of [`std::path::PathBuf`].
///
/// [`std::path::Path`]: https://doc.rust-lang.org/std/path/struct.PathBuf.html
#[derive(Debug, PartialEq)]
pub struct PathBuf {
inner: std::path::PathBuf,
}
@ -23,20 +24,18 @@ impl Into<std::path::PathBuf> for PathBuf {
impl From<OsString> for PathBuf {
fn from(path: OsString) -> PathBuf {
PathBuf {
inner: std::path::PathBuf::from(path),
}
std::path::PathBuf::from(path).into()
}
}
impl AsRef<Path> for PathBuf {
fn as_ref(&self) -> &Path {
Path::new(&self.inner)
impl From<&str> for PathBuf {
fn from(path: &str) -> PathBuf {
std::path::PathBuf::from(path).into()
}
}
impl std::fmt::Debug for PathBuf {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.inner, formatter)
impl AsRef<Path> for PathBuf {
fn as_ref(&self) -> &Path {
Path::new(&self.inner)
}
}

Loading…
Cancel
Save