Skip to content

Commit 3fd5141

Browse files
committed
impl AsRef<Path> for Cow<'_, str>
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()`.
1 parent f315c35 commit 3fd5141

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libstd/path.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,13 @@ impl AsRef<Path> for Cow<'_, OsStr> {
26622662
}
26632663
}
26642664

2665+
#[stable(feature = "cow_str_as_ref_path", since = "1.45.0")]
2666+
impl AsRef<Path> for Cow<'_, str> {
2667+
fn as_ref(&self) -> &Path {
2668+
Path::new::<str>(self.as_ref())
2669+
}
2670+
}
2671+
26652672
#[stable(feature = "rust1", since = "1.0.0")]
26662673
impl AsRef<Path> for OsString {
26672674
fn as_ref(&self) -> &Path {

0 commit comments

Comments
 (0)