# Stackoverflow when trying to use vec of different types using async

**URL:** <https://users.rust-lang.org/t/stackoverflow-when-trying-to-use-vec-of-different-types-using-async/102723>\
**Category:** uncategorized\
**Created:** [November 18, 2023, 10:37am UTC](https://users.rust-lang.org/t/stackoverflow-when-trying-to-use-vec-of-different-types-using-async/102723 "2023-11-18T10:37:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alphapage](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/alphapage/32/14613_2.png) [@Alphapage](https://users.rust-lang.org/u/Alphapage)\
**Post date:** [November 18, 2023, 10:37am UTC](https://users.rust-lang.org/t/stackoverflow-when-trying-to-use-vec-of-different-types-using-async/102723/1 "2023-11-18T10:37:16Z")

</div>

Hello,

> **[Rust Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=569020fe4ca540ccd47708ff556ef8ad)**
>
> A browser interface to the Rust compiler to experiment with the language

I am trying to use a vector of different types without enums, but I get a stackoverflow!

There is no concrete error thrown.

Thank you in advance for your help if you have any idea.

---

<div class="post-metadata">

**Author:** ![H2CO3](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@H2CO3](https://users.rust-lang.org/u/H2CO3)\
**Post date:** [November 18, 2023, 10:45am UTC](https://users.rust-lang.org/t/stackoverflow-when-trying-to-use-vec-of-different-types-using-async/102723/2 "2023-11-18T10:45:00Z")

</div>

Your blanket `DrawClone` and `Clone for Box<dyn Draw>` impls are infinitely mutually recursive for `T = Box<dyn Draw>` .

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/quinedot/32/17693_2.png) [@quinedot](https://users.rust-lang.org/u/quinedot)\
**Post date:** [November 18, 2023, 10:54am UTC](https://users.rust-lang.org/t/stackoverflow-when-trying-to-use-vec-of-different-types-using-async/102723/3 "2023-11-18T10:54:17Z")

</div>

[This](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=233738c833493502c9331eaf94c000bf) removes the infinite recursion for the `impl Clone` and at least let's the playground run. (I didn't do any further review at all.)

```diff
 impl Clone for Box<dyn Draw + Send + Sync> {
     fn clone(&self) -> Box<dyn Draw + Send + Sync> {
- self.clone_box()
+ (**self).clone_box()
     }
 }

```

That way you call `<dyn Draw + ... as DrawClone>::clone_box` instead of `<Box<dyn Draw + ...> as DrawClone>::clone_box` (recursively).

You seemed to get the idea with your `impl Draw for Box<dyn Draw + Send + Sync>`, so perhaps that's all you needed to understand what's going on, but if not [I have an example with more details here.](https://quinedot.github.io/rust-learning/dyn-trait-clone.html)

---

<div class="post-metadata">

**Author:** ![Alphapage](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/alphapage/32/14613_2.png) [@Alphapage](https://users.rust-lang.org/u/Alphapage)\
**Post date:** [November 18, 2023, 11:25am UTC](https://users.rust-lang.org/t/stackoverflow-when-trying-to-use-vec-of-different-types-using-async/102723/4 "2023-11-18T11:25:17Z")

</div>

> [@quinedot](#):
>
> [I have an example with more details here.](https://quinedot.github.io/rust-learning/dyn-trait-clone.html)

I should have read your helpful extra doc first.  
Thank you for pointing to this example.

---

<div class="post-metadata">

**Author:** ![keks993](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@keks993](https://users.rust-lang.org/u/keks993)\
**Post date:** [November 18, 2023, 3:47pm UTC](https://users.rust-lang.org/t/stackoverflow-when-trying-to-use-vec-of-different-types-using-async/102723/5 "2023-11-18T15:47:09Z")

</div>

I played around a little bit with your [example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a6b7e6b3b5fec011add0bc860ee0e80f). I removed the "double deref" and got surprisingly no infinite recursion. Why might this be the case here? 😲

**EDIT:** Ahh sorry, I was missing the forest through the trees. When I don't call clone it's clear that no infinite recursion happens. 🤣

---

<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:** [February 16, 2024, 3:47pm UTC](https://users.rust-lang.org/t/stackoverflow-when-trying-to-use-vec-of-different-types-using-async/102723/6 "2024-02-16T15:47:18Z")

</div>

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
