Converting collections using From/Into

Hi,
could the standard library feature From implementations for various collections such as

impl<T: Hash + Clone> From<HashSet<T>> for Vec<T> {
    fn from(set: HashSet<T>) -> Self {
        set.iter().map(Clone::clone).collect()
    }
}

in the future?

Is this a good idea?
Currently we can not implement this generic impl ourselves, because of

[rustc E0117] [E] only traits defined in the current crate can be implemented for arbitrary types

impl doesn't use only types from inside the current crate

note: define and implement a trait or new type instead

FWIW, you don't need Clone -- set.into_iter().collect()

You can even just Vec::from_iter(set), although FromIterator isn't in the prelude.

3 Likes