The DispatchFromDyn
trait allows for a type to "be self
" such that a trait can become object safe. For example, since Rc<T>
is DispatchFromDyn
, you can write code like
trait Foo {
fn foo(self: Rc<Self>);
}
and have a Box<dyn Foo>
be valid. This trait is defined in Rc like:
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Rc<U>> for Rc<T> {}
However, this implementation does not apply for custom allocators (e.g. Rc<T, A>
). This is the same in Arc and in both Rc and Arc's Weak, too. This means that replacing the above trait function with
fn foo(self: Rc<Self, MyAlloc>)
will not compile if you have a Box<dyn Foo>
.
Is this an oversight or is this intentional?