File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -664,6 +664,26 @@ impl Path {
664
664
pub fn to_path_buf ( & self ) -> PathBuf {
665
665
PathBuf :: from ( self . inner . to_path_buf ( ) )
666
666
}
667
+
668
+ /// Yields a [`&str`] slice if the `Path` is valid unicode.
669
+ ///
670
+ /// This conversion may entail doing a check for UTF-8 validity.
671
+ /// Note that validation is performed because non-UTF-8 strings are
672
+ /// perfectly valid for some OS.
673
+ ///
674
+ /// [`&str`]: https://doc.rust-lang.org/std/primitive.str.html
675
+ ///
676
+ /// # Examples
677
+ ///
678
+ /// ```
679
+ /// use async_std::path::Path;
680
+ ///
681
+ /// let path = Path::new("foo.txt");
682
+ /// assert_eq!(path.to_str(), Some("foo.txt"));
683
+ /// ```
684
+ pub fn to_str ( & self ) -> Option < & str > {
685
+ self . inner . to_str ( )
686
+ }
667
687
}
668
688
669
689
impl < ' a > From < & ' a std:: path:: Path > for & ' a Path {
You can’t perform that action at this time.
0 commit comments