Ok, I believe I understand my problem now:
This is where I started:
type FnTypeStatic = fn(&mut Input) -> Box<dyn Trait>;
Then I had a registry/collection (simplified, actually a dictionary)
static REGISTRY : Vec<FnTypeStatic> = {...};
And this was all working fine.
But, then I came over an interesting type with a lifetime, implementing Trait.
So I adjusted:
type FnTypeLifetime<'i> = fn(&mut Input<'i>) -> Box<dyn Trait + 'i >;
static REGISTRY:Vec<FnTypeLifetime<'i> = {...};
But this didn't work out, because of the unbound lifetime 'i in the static.
So I added the for clause:
type FnType = for<'i> fn(&mut Input<'i>) -> Box<dyn Trait + 'i >;
static REGISTRY:Vec<FnTypeLifetime> = {...};
Morally, this should work - it makes sense.
And it actually does: I just rewrote my whole machine, with lots of dyn Trait +'i
, and it just works fine.
So, thank you all for your help!
Why didn't I notice this before?
When I was write the code for the static use case, I wanted to be generic over traits.
Unfortunately, this is not possible (right?).
So I wrote my code to be generic over dyn Trait
instead.
The actual starting point was
type FnTypeStatic<T> = fn(&mut Input) -> Box<T>;
and then I added my lifetime like this
type FnTypeStatic<'i, T:'i> = fn(&mut Input<'i>) -> Box<T>;
and then I lost the right track when trying to figure out how to do this
First specializing to a fixed trait and then implementing the lifetime turned out to be much easier than the other way around.
New Question: Is there some syntax for the (restricted, dependent) product
type FnTypeStatic<T> = for<'i> where T:'i fn(&mut Input<'i>) -> Box<T>;
(The lifetime-in-a-box syntax works only for traits ...)