Cow<str> to Cow<Path>

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?

1 Like

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.

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.


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

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.