Cow<str> to Cow<Path>


#1

It’s entirely too difficult to convert a Cow<str> (in my case, obtained from String::from_utf8_lossy into a Cow<Path>, even though it’s very easy to go from str/String to Path/PathBuf. Maybe I’m missing something?

Anyway, it seems to me that a general conversion between Cow<A> and Cow<B> would be a useful addition to standard library, assuming there’s proper conversion trait implementations from A to B and from A::Owned to B::Owned. Is this something that could be added?


#2

Actually, its worth noting to that there’s no impl of From<&'a str> for &'a Path either. Both this and the missing impl for Cows seem like an oversight to me.


#3

impl<'a, A: 'a + ToOwned + ?Sized, B: 'a + ToOwned + ?Sized> From<Cow<'a, A>> for Cow<'a, B> where &'a B : From<&'a A>, B::Owned : From<A::Owned> might work; not sure off the top of my head.

impl<'a> From<&'a str> for &'a Path probably makes sense.


#4

Probably impl<'a, S> From<&'a S> for &'a Path where S: AsRef<OsStr> + ?Sized.