@@ -462,29 +462,6 @@ impl Path {
462
462
fs:: metadata ( self ) . await
463
463
}
464
464
465
- /// Queries the metadata about a file without following symlinks.
466
- ///
467
- /// This is an alias to [`fs::symlink_metadata`].
468
- ///
469
- /// [`fs::symlink_metadata`]: ../fs/fn.symlink_metadata.html
470
- ///
471
- /// # Examples
472
- ///
473
- /// ```no_run
474
- /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
475
- /// #
476
- /// use async_std::path::Path;
477
- ///
478
- /// let path = Path::new("/Minas/tirith");
479
- /// let metadata = path.symlink_metadata().await.expect("symlink_metadata call failed");
480
- /// println!("{:?}", metadata.file_type());
481
- /// #
482
- /// # Ok(()) }) }
483
- /// ```
484
- pub async fn symlink_metadata ( & self ) -> io:: Result < fs:: Metadata > {
485
- fs:: symlink_metadata ( self ) . await
486
- }
487
-
488
465
/// Directly wraps a string slice as a `Path` slice.
489
466
///
490
467
/// This is a cost-free conversion.
@@ -511,6 +488,52 @@ impl Path {
511
488
unsafe { & * ( std:: path:: Path :: new ( s) as * const std:: path:: Path as * const Path ) }
512
489
}
513
490
491
+ /// Returns the `Path` without its final component, if there is one.
492
+ ///
493
+ /// Returns [`None`] if the path terminates in a root or prefix.
494
+ ///
495
+ /// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
496
+ ///
497
+ /// # Examples
498
+ ///
499
+ /// ```
500
+ /// use async_std::path::Path;
501
+ ///
502
+ /// let path = Path::new("/foo/bar");
503
+ /// let parent = path.parent().unwrap();
504
+ /// assert_eq!(parent, Path::new("/foo"));
505
+ ///
506
+ /// let grand_parent = parent.parent().unwrap();
507
+ /// assert_eq!(grand_parent, Path::new("/"));
508
+ /// assert_eq!(grand_parent.parent(), None);
509
+ /// ```
510
+ pub fn parent ( & self ) -> Option < & Path > {
511
+ self . inner . parent ( ) . map ( |p| p. into ( ) )
512
+ }
513
+
514
+ /// Queries the metadata about a file without following symlinks.
515
+ ///
516
+ /// This is an alias to [`fs::symlink_metadata`].
517
+ ///
518
+ /// [`fs::symlink_metadata`]: ../fs/fn.symlink_metadata.html
519
+ ///
520
+ /// # Examples
521
+ ///
522
+ /// ```no_run
523
+ /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
524
+ /// #
525
+ /// use async_std::path::Path;
526
+ ///
527
+ /// let path = Path::new("/Minas/tirith");
528
+ /// let metadata = path.symlink_metadata().await.expect("symlink_metadata call failed");
529
+ /// println!("{:?}", metadata.file_type());
530
+ /// #
531
+ /// # Ok(()) }) }
532
+ /// ```
533
+ pub async fn symlink_metadata ( & self ) -> io:: Result < fs:: Metadata > {
534
+ fs:: symlink_metadata ( self ) . await
535
+ }
536
+
514
537
/// Converts a `Path` to an owned [`PathBuf`].
515
538
///
516
539
/// [`PathBuf`]: struct.PathBuf.html
0 commit comments