It can be useful to feature dyn Traits with "generic methods":
#[dyn_safe(true)] // Error, `SpawnFut` cannot be made into a `dyn` object
trait SpawnFut {
fn spawn_fut (&self, f: impl 'static + Future<Output = ()>)
;
}
In that case, when there is a way to "go dyn and back", such as impl Future -> Pin<Box<dyn Future>> : impl Future, it is possible to feature a dyn SpawnFut API:
use ::core::{future::Future, pin::Pin};
#[dyn_safe(true)] // <- objective
trait SpawnFut : NonGenericSpawnFut {
fn spawn_fut (&self, f: impl 'static + Future<Output = ()>)
where
Self : Sized,
;
}
fn objective (s: &'_ dyn SpawnFut)
{
s.dyn_spawn_fut(async {});
}
fn main ()
{
struct Implementor();
impl SpawnFut for Implementor {
fn spawn_fut (&self, _: impl 'static + Future<Output = ()>)
where
Self : Sized,
{}
}
objective(&Implementor())
}
// ---
trait NonGenericSpawnFut {
fn non_generic_spawn_fut (&self, f: Pin<Box<dyn 'static + Future<Output = ()>>>)
;
}
impl<S : SpawnFut> NonGenericSpawnFut for S {
fn non_generic_spawn_fut (&self, f: Pin<Box<dyn 'static + Future<Output = ()>>>)
{
self.spawn_fut(f)
}
}
impl dyn '_ + SpawnFut {
fn dyn_spawn_fut (&self, f: impl 'static + Future<Output = ()>)
{
self.non_generic_spawn_fut(Box::pin(f))
}
}
-
Playground
-
Ideally, .dyn_spawn_fut() could be named .spawn_fut(), for even more magic, but for some reason Rust gets confused in that case 
Now, this example does not feature impl Trait for dyn …, only impl dyn …; but it's easy to imagine how the former can still be useful: imagine that SpawnFut comes from an external crate, and that they did not feature that very convenient .dyn_spawn_fut() method.
In that case you could use the extension trait pattern to imbue dyn SpawnFut with your own convenience methods:
use ::external_crate::SpawnFut;
/// Extension trait!
#[dyn_safe(false)] // No more need for `dyn` here.
trait DynSpawnFut {
/// Desired method's signature that we want to add.
fn dyn_spawn_fut (&self, f: impl 'static + Future<Output = ()>)
;
}
impl DynSpawnFut for dyn '_ + SpawnFut {
fn dyn_spawn_fut (&self, f: impl 'static + Future<Output = ()>)
{
self.non_generic_spawn_fut(Box::pin(f))
}
}
Another example is to handle the case where somebody may write:
#[dyn_safe(true)]
trait SpawnFutAndMore : SpawnFut { … }
And then they would like to call .dyn_spawn_fut() on a dyn SpawnFutAndMore. With the inherent impl, this would not be possible. But with the extension trait approach, one can easily write:
impl<DynObject : ?Sized> DynSpawnFut for DynObject
where
DynObject : SpawnFut,
{
fn dyn_spawn_fut (&self, f: impl 'static + Future<Output = ()>)
{
self.non_generic_spawn_fut(Box::pin(f))
}
}
then,
fn objective (s: &'_ dyn SpawnFutAndMore)
{
s.dyn_spawn_fut(async { … });
}
will work 