# \`Rc/Arc::Borrowed\`: An object-safe version of \`&Rc\<T\>\`/\`&Arc\<T\>\`

**URL:** <https://internals.rust-lang.org/t/rc-arc-borrowed-an-object-safe-version-of-rc-t-arc-t/8896>\
**Category:** Uncategorized\
**Created:** [November 25, 2018, 1:04am UTC](https://internals.rust-lang.org/t/rc-arc-borrowed-an-object-safe-version-of-rc-t-arc-t/8896 "2018-11-25T01:04:57Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![kennytm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kennytm/32/161_2.png) [@kennytm](https://internals.rust-lang.org/u/kennytm)\
**Post date:** [November 25, 2018, 2:59am UTC](https://internals.rust-lang.org/t/rc-arc-borrowed-an-object-safe-version-of-rc-t-arc-t/8896/3 "2018-11-25T02:59:59Z")

</div>

This has nothing to do with `arbitrary_self_type`, but [DispatchFromDyn](https://github.com/rust-lang/rust/pull/54383).

The problem is `&Rc<dyn Trait>` currently is a _thin_ pointer like `&(Rc<()>, &VTable)`, not the regular DST representation like `(&Rc<()>, &VTable)`. (There is no unsize-coercion relationship to `&Rc<dyn Trait>` from `&Rc<T>`.) So the compiler cannot generate the code for dynamic dispatch of `&Rc<dyn Trait>` like the single-pointer counterpart:

```rust
fn dyn_dispatch_rc(self: Rc<dyn Trait>) {
    let vtable = metadata(self);
    (vtable.fptr_of_method)(self as Rc<()>)
    // ^ just take the thin pointer part
}

```

However I don’t think we need to introduce this `Borrow` type either. We just need to tell the compiler to obtain the vtable not from the pointer itself, but its pointee:

```rust
fn dyn_dispatch_rc_ref(self: &Rc<dyn Trait>) {
    let vtable = metadata(*self); // ← take *self not self
    (vtable.fptr_of_method)(self as &Rc<()>)
    // object-slice the metadata part away
}

```

Meaning we should change the `DispatchFromDyn` trait to require a method to extract the vtable

```rust
trait DispatchFromDyn<T> {
    fn vtable(dst: &T) -> &'static VTable;
}
impl DispatchFromDyn<Rc<U>> for Rc<T> {
    fn vtable(dst: &Rc<U>) -> &'static VTable {
        metadata(*dst)
    }
}
impl DispatchFromDyn<&Rc<U>> for &Rc<T> {
    fn vtable(dst: &&Rc<U>) -> &'static VTable {
        metadata(**dst)
    }
}

```

---

_[View the full topic](https://internals.rust-lang.org/t/rc-arc-borrowed-an-object-safe-version-of-rc-t-arc-t/8896)._
