File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -684,6 +684,31 @@ impl Path {
684
684
pub fn to_str ( & self ) -> Option < & str > {
685
685
self . inner . to_str ( )
686
686
}
687
+
688
+ /// Converts a `Path` to a [`Cow<str>`].
689
+ ///
690
+ /// Any non-Unicode sequences are replaced with
691
+ /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD].
692
+ ///
693
+ /// [`Cow<str>`]: https://doc.rust-lang.org/std/borrow/enum.Cow.html
694
+ /// [U+FFFD]: https://doc.rust-lang.org/std/char/constant.REPLACEMENT_CHARACTER.html
695
+ ///
696
+ /// # Examples
697
+ ///
698
+ /// Calling `to_string_lossy` on a `Path` with valid unicode:
699
+ ///
700
+ /// ```
701
+ /// use async_std::path::Path;
702
+ ///
703
+ /// let path = Path::new("foo.txt");
704
+ /// assert_eq!(path.to_string_lossy(), "foo.txt");
705
+ /// ```
706
+ ///
707
+ /// Had `path` contained invalid unicode, the `to_string_lossy` call might
708
+ /// have returned `"fo�.txt"`.
709
+ pub fn to_string_lossy ( & self ) -> std:: borrow:: Cow < ' _ , str > {
710
+ self . inner . to_string_lossy ( )
711
+ }
687
712
}
688
713
689
714
impl < ' a > From < & ' a std:: path:: Path > for & ' a Path {
You can’t perform that action at this time.
0 commit comments