mirror of
https://github.com/async-rs/async-std.git
synced 2025-02-06 20:55:33 +00:00
Implemented Path::to_string_lossy
This commit is contained in:
parent
ea43d7fd29
commit
a17b017e01
1 changed files with 25 additions and 0 deletions
|
@ -684,6 +684,31 @@ impl Path {
|
|||
pub fn to_str(&self) -> Option<&str> {
|
||||
self.inner.to_str()
|
||||
}
|
||||
|
||||
/// Converts a `Path` to a [`Cow<str>`].
|
||||
///
|
||||
/// Any non-Unicode sequences are replaced with
|
||||
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD].
|
||||
///
|
||||
/// [`Cow<str>`]: https://doc.rust-lang.org/std/borrow/enum.Cow.html
|
||||
/// [U+FFFD]: https://doc.rust-lang.org/std/char/constant.REPLACEMENT_CHARACTER.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Calling `to_string_lossy` on a `Path` with valid unicode:
|
||||
///
|
||||
/// ```
|
||||
/// use async_std::path::Path;
|
||||
///
|
||||
/// let path = Path::new("foo.txt");
|
||||
/// assert_eq!(path.to_string_lossy(), "foo.txt");
|
||||
/// ```
|
||||
///
|
||||
/// Had `path` contained invalid unicode, the `to_string_lossy` call might
|
||||
/// have returned `"fo<66>.txt"`.
|
||||
pub fn to_string_lossy(&self) -> std::borrow::Cow<'_, str> {
|
||||
self.inner.to_string_lossy()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a std::path::Path> for &'a Path {
|
||||
|
|
Loading…
Reference in a new issue