# Casting TraitObject to Super Trait

**URL:** <https://users.rust-lang.org/t/casting-traitobject-to-super-trait/33524>\
**Category:** uncategorized\
**Created:** [October 12, 2019, 5:18pm UTC](https://users.rust-lang.org/t/casting-traitobject-to-super-trait/33524 "2019-10-12T17:18:15Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![RustyYato](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/rustyyato/32/49247_2.png) [@RustyYato](https://users.rust-lang.org/u/RustyYato)\
**Post date:** [October 13, 2019, 2:25pm UTC](https://users.rust-lang.org/t/casting-traitobject-to-super-trait/33524/7 "2019-10-13T14:25:15Z")

</div>

Trait objects have an unspecified layout, so you can't know the order that the methods show up in the vtable. If you try to rely on the layout, you will invoke UB.

The only way to do this conversion safely is to provide methods that convert to the super trait

You could even extract the conversion functions into their own trait [like so](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f31577fc3c5334c9e2742dd57124eb51).

---

_[View the full topic](https://users.rust-lang.org/t/casting-traitobject-to-super-trait/33524)._
