"Dyn" object, a type-erased pointer to an object and a vtable for protocol functions.
type &dyn P = dyn<(P, ), &void>
type &mut dyn P = dyn<(P, ), &mut void>
type &dyn (P1 + P2) = dyn<(P1, P2), &void>
Example
protocol Foo<Self> { fn foo(self: &Self); }
struct Bar {};
impl Bar {
fn foo(self: &Bar) { println!("Bar::foo"); }
}
struct Quux {};
impl Quux {
fn foo(self: &Quux) { println!("Quux::foo"); }
}
let bar: &dyn Foo<Self> = &Bar {};
let quux: &dyn Foo<Self> = &Quux {};
bar.foo(); // prints "Bar::foo"
quux.foo(); // prints "Quux::foo"
Run this example