From 3fd5141361b7ed7fe88b3fed7007f302683ec176 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Tue, 16 Jun 2020 12:16:15 +0800 Subject: [PATCH] impl AsRef for Cow<'_, str> There is already `impl AsRef for str` and `impl<'_> AsRef for Cow<'_, OsStr>` but one still need to do `s.as_ref()` for functions that takes in `AsRef` for `Cow<'_ str>` such as `Path::join()`. --- src/libstd/path.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 8ff7508ba6457..8582122dee327 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -2662,6 +2662,13 @@ impl AsRef for Cow<'_, OsStr> { } } +#[stable(feature = "cow_str_as_ref_path", since = "1.45.0")] +impl AsRef for Cow<'_, str> { + fn as_ref(&self) -> &Path { + Path::new::(self.as_ref()) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl AsRef for OsString { fn as_ref(&self) -> &Path {