I've been writing a lot of functions that have parameters with the type impl Into<Cow<'a, T>>
, as these functions need to take ownership of the value, but it's messy to have .clone() dotted around in the places that call these functions.
Unfortunately, not many external types implement Into<Cow>. While my knowledge of Rust is still limited, it seems to me this could be automatically implemented with:
impl<'a, T: ToOwned> From<&'a T> for Cow<'a, T> {
fn from(x: &'a T) -> Cow<'a, T> {
Cow::Borrowed(x)
}
}
impl<'a, T: ToOwned> From<T> for Cow<'a, T> {
fn from(x: T) -> Cow<'a, T> {
Cow::Owned(x)
}
}
I assume I'm missing an obvious reason why this isn't in the standard library, but otherwise it would be nice to see it there.