File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 1
- use std:: path:: { Path , PathBuf } ;
2
-
3
1
use crate :: io;
2
+ use crate :: path:: { Path , PathBuf } ;
4
3
use crate :: task:: blocking;
5
4
6
5
/// Reads a symbolic link and returns the path it points to.
@@ -28,6 +27,8 @@ use crate::task::blocking;
28
27
/// # Ok(()) }) }
29
28
/// ```
30
29
pub async fn read_link < P : AsRef < Path > > ( path : P ) -> io:: Result < PathBuf > {
31
- let path = path. as_ref ( ) . to_owned ( ) ;
32
- blocking:: spawn ( async move { std:: fs:: read_link ( path) } ) . await
30
+ let path: std:: path:: PathBuf = path. as_ref ( ) . to_path_buf ( ) . into ( ) ;
31
+ Ok ( blocking:: spawn ( async move { std:: fs:: read_link ( path) } )
32
+ . await ?
33
+ . into ( ) )
33
34
}
Original file line number Diff line number Diff line change @@ -529,6 +529,7 @@ impl Path {
529
529
/// #
530
530
/// use async_std::path::Path;
531
531
/// use async_std::fs;
532
+ /// use futures_util::stream::StreamExt;
532
533
///
533
534
/// let path = Path::new("/laputa");
534
535
/// let mut dir = fs::read_dir(&path).await.expect("read_dir call failed");
@@ -543,6 +544,28 @@ impl Path {
543
544
fs:: read_dir ( self ) . await
544
545
}
545
546
547
+ /// Reads a symbolic link, returning the file that the link points to.
548
+ ///
549
+ /// This is an alias to [`fs::read_link`].
550
+ ///
551
+ /// [`fs::read_link`]: ../fs/fn.read_link.html
552
+ ///
553
+ /// # Examples
554
+ ///
555
+ /// ```no_run
556
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
557
+ /// #
558
+ /// use async_std::path::Path;
559
+ ///
560
+ /// let path = Path::new("/laputa/sky_castle.rs");
561
+ /// let path_link = path.read_link().await.expect("read_link call failed");
562
+ /// #
563
+ /// # Ok(()) }) }
564
+ /// ```
565
+ pub async fn read_link ( & self ) -> io:: Result < PathBuf > {
566
+ fs:: read_link ( self ) . await
567
+ }
568
+
546
569
/// Queries the metadata about a file without following symlinks.
547
570
///
548
571
/// This is an alias to [`fs::symlink_metadata`].
You can’t perform that action at this time.
0 commit comments