# Associated type "inherits" sizedness of \`Self\`?

**URL:** <https://users.rust-lang.org/t/associated-type-inherits-sizedness-of-self/99473>\
**Category:** help\
**Created:** [September 5, 2023, 10:09pm UTC](https://users.rust-lang.org/t/associated-type-inherits-sizedness-of-self/99473 "2023-09-05T22:09:52Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [September 6, 2023, 7:56pm UTC](https://users.rust-lang.org/t/associated-type-inherits-sizedness-of-self/99473/5 "2023-09-06T19:56:01Z")

</div>

> [@joshlf](#):
>
> some clever hack

Hmm… let’s take some [type equality trait](https://docs.rs/into_ext/latest/into_ext/trait.TypeIsEqual.html), and then we can start with

```rust
trait Foo {
    type Bar: ?Sized;
}

```

and add a second associated type equal to the first, and bounded by `Sized` … i.e. like this:

```rust
pub trait TypeIsEqual {
    type To: ?Sized;
}
impl<T: ?Sized> TypeIsEqual for T {
    type To = Self;
}

trait Foo {
    type Bar: ?Sized;
    type BarSized: Sized + TypeIsEqual<To = Self::Bar>
    where
        Self: Sized;
}

```

(I know the `BarSized: Sized` bound is redundant, but it’s more explicit this way)

Now the hackiness level of this is quite high. (In fact it’s already nontrivial to implement this _at all_ for some non-`Sized` type.) This trait definition certainly not very comfortable to work with, in fact depending on what your exact use-case is like, it may probably not be usable at all.

On that matter, feel free to actually do share more about your use-case, then we could discuss the trickeries that _could_ make this approach actually work.

---

_[View the full topic](https://users.rust-lang.org/t/associated-type-inherits-sizedness-of-self/99473)._
