Skip to content

Commit

Permalink
impl AsRef<Path> for Cow<'_, str>
Browse files Browse the repository at this point in the history
There is already `impl AsRef<OsStr> for str` and
`impl<'_> AsRef<Path> for Cow<'_, OsStr>` but one still need to do
`s.as_ref()` for functions that takes in `AsRef<Path>` for `Cow<'_ str>`
such as `Path::join()`.
  • Loading branch information
pickfire committed Jun 16, 2020
1 parent f315c35 commit 3fd5141
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2662,6 +2662,13 @@ impl AsRef<Path> for Cow<'_, OsStr> {
}
}

#[stable(feature = "cow_str_as_ref_path", since = "1.45.0")]
impl AsRef<Path> for Cow<'_, str> {
fn as_ref(&self) -> &Path {
Path::new::<str>(self.as_ref())
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for OsString {
fn as_ref(&self) -> &Path {
Expand Down

0 comments on commit 3fd5141

Please sign in to comment.