# Converting collections using From/Into

**URL:** <https://users.rust-lang.org/t/converting-collections-using-from-into/38863>\
**Category:** community\
**Created:** [February 29, 2020, 12:33am UTC](https://users.rust-lang.org/t/converting-collections-using-from-into/38863 "2020-02-29T00:33:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mankinskin](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mankinskin/32/46764_2.png) [@mankinskin](https://users.rust-lang.org/u/mankinskin)\
**Post date:** [February 29, 2020, 12:33am UTC](https://users.rust-lang.org/t/converting-collections-using-from-into/38863/1 "2020-02-29T00:33:36Z")

</div>

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

```rust
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

```rust
[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

```

---

<div class="post-metadata">

**Author:** ![cuviper](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/cuviper/32/3156_2.png) [@cuviper](https://users.rust-lang.org/u/cuviper)\
**Post date:** [February 29, 2020, 12:43am UTC](https://users.rust-lang.org/t/converting-collections-using-from-into/38863/2 "2020-02-29T00:43:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [May 29, 2020, 12:43am UTC](https://users.rust-lang.org/t/converting-collections-using-from-into/38863/3 "2020-05-29T00:43:40Z")

</div>

Closed on May 29, 2020, 12:43am UTC

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