use impl_trait::impl_trait; struct Foo; trait Bar {} impl_trait! { /// Yes, you can write docs here. impl Foo { /// You can write docs here too. fn as_dyn_bar(&self) -> &dyn Bar { self } /// You can even write docs here! impl trait Bar { } } } fn main() {}