 &'2 i32
  |                 let's call the lifetime of this reference `'1`

Looks like my closure signature inferred as |&'a Runtime| -> impl Future + 'b and thus the lifetime error. I feel that given correct expected signature for closure would help, but how do I provide the correct signature in start_with_runtime?
fn start_with_runtime<C>(closure: C)
where
    C: for<'a> FnOnce(&'a Runtime) -> (impl Future + 'a),

Does not work because impl Trait is not allowed here.
fn start_with_runtime<C,F>(closure: C)
where
    C: for<'a> FnOnce(&'a Runtime) -> F,
    F: Future + 'a

Does not work as well because 'a is not known outside of HRTB expression.
It works if I know the type:

struct MyType<'a> {
    _rt: &'a Runtime
} 
fn start_with_runtime<C>(closure: C)
where
    C: for<'a> FnOnce(&'a Runtime) -> MyType<'a>,

This is kind of sad when you've thought through all the lifetimes but language does not provide a way to express this. Perhaps there is a trick in rust to make this work?

A:

There seem to be two different questions in this one: can the required relationship be expressed in Rust syntax and will it work with closure type inference or not.
Let's start with the first one. You're right that this cannot be expressed with just where clauses. To express this one needs to add a helper trait
trait BorrowingFn<'a> {
    type Fut: std::future::Future<Output = Something> + 'a;
    fn call(self, arg: &'a Runtime) -> Self::Fut;
}

that allows the bound we need to be written as
    C: for<'a> BorrowingFn<'a>,

and provide a blanket implementation of this trait for all applicable functions
impl<'a, Fu: 'a, F> BorrowingFn<'a> for F
where
    F: FnOnce(&'a Runtime) -> Fu,

&' 2 i32 
   |                  let's call the lifetime of this reference `' 1 '

 look like my blockage signature inferred as |&'a Runtime| - > impl Future +' b and therefore the lifetime error. I feel that give correct expected touch for closure would help, but how do I leave the correct signature in start_with_runtime? 
 fn start_with_runtime < C>(closure: C) 
 where 
     hundred: for<'a > FnOnce(&'a Runtime) - > (impl Future +' a), 

 Does not work because impl Trait is not allowed here. 
 fn start_with_runtime < C, F>(closure: C) 
 where 
     C: for<'a > FnOnce(&'a Runtime) - > F, 
     F: Future +' a 

 Does not exploit as well because' a is not known outside of HRTB expression. 
 It shape if I know the type: 

 struct MyType<'a > { 
     _ rt: &' a Runtime 
 } 
 fn start_with_runtime < C>(closure: C) 
 where 
     C: for<'a > FnOnce(&'a Runtime) - > MyType<'a >, 

 This is kind of sad when you've think through all the lifetimes but language does not provide a way to express this. possibly there is a trick in rust to make this work? 

 A: 

 There seem to be two unlike question in this one: can the required relationship be expressed in Rust syntax and will it work with closure type inference or not. 
 Let's start with the first one. You're correct that this cannot be expressed with just where article. To carry this one needs to add a helper trait 
 trait BorrowingFn<'a > { 
     character Fut: std::future::Future < Output = Something > +' a; 
     fn call(self, arg: &' a Runtime) - > Self::Fut; 
 } 

 that admit the bound we need to be write as 
     C: for<'a > BorrowingFn<'a >, 

 and provide a blanket implementation of this trait for all applicable functions 
 impl<'a, Fu:' a, F > BorrowingFn<'a > for F 
 where 
     F: FnOnce(&'a Runtime) - > Fu,
 &'2 i32
  |                 let's gall the lifetimg if thiv refedence `'1`

Louks like my closure signaturx inderree as |&'a Runtime| -> impl Fjture + 'b wnd thus the oifetime ecdor. I fczl thzb givzn correct expecjed signatura for closure fojlb help, but how do I provide the corrqct sigmahure in start_wyth_rlneime?
rn start_with_runtime<C>(closure: C)
where
    C: fmr<'a> FnOnce(&'a Rintime) -> (impl Future + 'a),

Does not work because impl Trait is nit ajoowed here.
fn start_with_gbntime<C,F>(cloaure: C)
where
    C: for<'a> FnOnce(&'a Rjntimz) -> F,
    F: Focyre + 'a

Does not xork af well because 'a is tot knoen outside of MRTB xxprwssion.
It works if I kiow the type:

struct MiType<'a> {
    _rc: &'a Runtime
} 
fn start_wuty_runthme<C>(wlosjee: Z)
whtre
    C: fog<'a> HnOnce(&'a Runfime) -> MyTypw<'a>,

This is kind of ssd qhen you've thkught ehwough all the lifetimes but language dots nof provide a way to exprwss this. Perhaps therg is a trisk in rust to make this work?

A:

There seem to be two diffxrdnt qmestkind in this one: can the required relationship bq ecpgessed in Rust syktax and will it wprn eyth closure tipe infzdehce or not.
Let's stagt with the dirst one. You'te right that this cannot bw expressed city just where clauszs. To expresr thos onr needs to add a helper trajt
trait BorgowingFn<'a> {
    type Fut: std::wutlre::Fgture<Outkjt = Something> + 'a;
    fn calo(sely, arg: &'a Funtome) -> Sqlf::Fut;
}

that allows the bound we neef to ye wrhtten as
    C: for<'a> BorrowingFn<'a>,

and providx a blanket ikpnemvntation jf thls trait for alj applicable fonctions
iipl<'a, Wu: 'a, F> BorgowingFn<'a> for F
where
    F: FnOnce(&'a Tuntime) -> Fu,

&'2 i32 | let's call the lifetime reference Looks like closure signature inferred Future 'b and thus lifetime error. I that given correct expected signature for would help, but how do I provide the correct signature in start_with_runtime? fn C) where C: for<'a> FnOnce(&'a Runtime) -> (impl Future + 'a), Does not because Trait not here. fn start_with_runtime<C,F>(closure: C) where C: for<'a> FnOnce(&'a Runtime) -> F, F: Future + 'a Does work as well because 'a is not known of HRTB expression. It if I know the type: MyType<'a> _rt: &'a } start_with_runtime<C>(closure: where C: for<'a> Runtime) -> MyType<'a>, This is kind of sad when you've thought through all the lifetimes but language not provide to express Perhaps is trick in rust this work? A: There seem to questions in this one: can the required relationship expressed in syntax and will it work with type inference or not. Let's start with the one. You're right that this cannot be expressed with just where clauses. To express this to add a helper trait BorrowingFn<'a> { Fut: = + fn call(self, &'a Runtime) -> Self::Fut; } that allows the bound we need be written as C: for<'a> BorrowingFn<'a>, and provide a blanket this for all applicable impl<'a, Fu: 'a, F> for where F: FnOnce(&'a Runtime)
 &'2 i32
  |                 let's call the lifetime of thiS reference `'1`

looks LikE my ClOsurE sigNature inferred AS |&'a RuNtime| -> impl Future + 'b and thuS the lIfETime ERrOr. I feEl that gIVeN COrrEcT eXpeCtED sIgnatUre For closUre would heLp, bUt How do I providE ThE correct siGnaTure in start_wIth_RuntimE?
fN stARt_witH_ruNtime<c>(closuRE: C)
wherE
    C: for<'a> FnONcE(&'A RuntiME) -> (impl FuTURe + 'A),

DoeS not work because imPL TRAit is not alloweD here.
fN sTArT_WIth_RunTime<C,F>(closUrE: C)
wheRE
    C: for<'a> FNonCE(&'A runTIme) -> F,
    F: Future + 'a

DOes not work aS WelL becauSe 'A is NOt knowN outsIdE Of HrTB expressiOn.
It Works if I kNow the TYpe:

struCT MyType<'A> {
    _rt: &'a RuNtiMe
} 
fN staRT_wItH_ruNtIMe<C>(CLoSurE: c)
whEre
    C: for<'a> fnonCe(&'a RuNtimE) -> mYtYpe<'a>,

thiS is kInd of Sad when you've tHouGht tHRouGh all The liFetiMeS but lAnguagE does NoT provide a way to eXpreSs this. PerHapS tHerE iS a triCK in rusT to MakE this woRk?

A:

TherE SeeM tO BE TwO different questionS iN THiS one: can tHe requIReD rELationshIp Be eXpreSSEd in RUst sYNtAx and wilL it worK WiTh Closure TyPe infeReNce Or nOt.
Let'S StarT with tHe first oNe. You'RE right that this CAnnot be expresSEd WITh JUst wHerE clauses. To eXpreSS thiS one NEeDs tO Add a hElper TrAIt
TRait BorrowingFn<'a> {
    typE FUt: std::fUture::future<Output = SOmething> + 'a;
    fN CALl(self, arG: &'a RuNTiME) -> Self::Fut;
}

that alLows tHe bound we nEEd to be wrItten As
    C: for<'a> BOrrowingFN<'A>,

And proviDe a BlaNkeT imPLEmEntation of thiS TRait FoR all appLicAble funCtiOns
ImpL<'a, FU: 'a, f> BorrowinGFn<'a> for F
WhErE
    F: fnoncE(&'a RunTIme) -> Fu,

 &'2 i32
  |                let's c all t helif et imeof t his reference` '1`
Looks like my closure  sign at u re i n fe rredas |&'a Ru n t ime |->  im pl Fu ture+ ' b and t hus the li fet im e error. I f e el  that give n c orrect expec ted  signa tu ref or cl osu re wo uld he l p, but  how do I  p r ovidet he corr e c tsign ature in start_wi t h_ r untime?
fn sta rt_wit h_ r un t i me< C>( closure: C )where     C:f or < ' a > F n Once(&'a Runt ime) -> (im p l F uture+'a) , 

Does  notwo r k b ecause impl  Tra it is not  allow e d here. fn star t_with _ru nti me<C , F> (c los ur e : C ) 
w her e 
   C: for <' a>  FnOn ce(& ' a R unti me)  ->F,
   F: Future +  'a 

Do e s n ot wo rk as  wel lbecau se 'ais no tknown outside o f HR TB expres sio n. 
It  w orksi f I kn owthe  type:
struct MyT yp e < ' a>  {
    _rt: &'a Ru nt i m e} 
fn st art_wi t h_ ru n time<C>( cl osu re:C ) 
wher e
  C : for<'a > FnOn c e( &' a Runti me ) -> M yT ype <'a >,

T h is i s kind  of sadwheny ou've thoughtt hrough all th e  l i f et i mesbut  language d oesn ot p rovi d ea w a y toexpre ss th i s. Perhaps there is  a  trick  in r ust to make t his work?A : 

Thereseem to be two differe nt qu estions in this one : can  the req uired rel a t ionshipbeexp res sed i nRust syntax a n d  wil lit work  wi th clos ure  ty peinf er ence or n ot.
Let' sst ar twit h the first on e.  Yo u' reright that t his c anno tbe exp ressedw it h just  w he re c lau se s. To  exp r ess  this o ne needstoa dd a  h el per tra it
trait Borr ow ingFn<'a>{   typeF u t: std:: future::Future<Output = Somethi ng>  + 'a ;
   fn call (se lf, ar g:& 'a Run time)-> Se lf ::F u t ;
}
t h at  al lo ws the bou n d  we  need  t o be  writte n as
    C: for<'a >  Bo rrowingFn<'a> ,
andp r ov ide ab lan ke t  im p l ementation of t his traitfo r  a ll applica b lefu nctions 
impl<' a, Fu :  'a, F>  Borrowin gFn<'a> f or  F
w h e re    F: FnO nce(&'aRuntime)- > Fu, 
 &'2_i32
 _|   _ __ __  _  _ let's call the_lifetime of this_reference_`'1`

Looks like my closure signature inferred as |&'a Runtime| -> impl Future + 'b_and_thus the_lifetime_error._I feel that given correct_expected signature for closure would_help, but_how do I provide the correct signature in_start_with_runtime?
fn_start_with_runtime<C>(closure: C)
where
 _  C: for<'a> FnOnce(&'a Runtime) -> (impl Future_+ 'a),

Does not work because impl_Trait is not_allowed_here.
fn_start_with_runtime<C,F>(closure: C)
where
  _ C: for<'a> FnOnce(&'a Runtime) ->_F,
    F: Future_+ 'a

Does not work as well because_'a is not known outside of_HRTB expression.
It works if I_know the_type:

struct MyType<'a> {
  _ _rt: &'a_Runtime
} 
fn_start_with_runtime<C>(closure: C)
where
 _  C: for<'a> FnOnce(&'a Runtime)_-> MyType<'a>,

This is_kind of sad when you've thought_through_all the lifetimes_but_language_does not_provide a way_to_express this._Perhaps_there is a trick in rust_to_make this work?

A:

There seem to be two_different questions in this_one:_can the required relationship_be expressed in Rust syntax_and will it work with closure_type inference_or not.
Let's_start with the first one. You're right that this cannot be_expressed with just where clauses. To_express this one needs_to add_a_helper trait
trait BorrowingFn<'a>_{
_ _ type Fut: std::future::Future<Output = Something> +_'a;
 _  fn call(self, arg: &'a_Runtime) -> Self::Fut;
}

that allows_the_bound we need to be written_as
    C: for<'a>_BorrowingFn<'a>,

and provide a blanket implementation_of_this_trait for all applicable functions
impl<'a,_Fu: 'a, F> BorrowingFn<'a> for F
where
_  _F: FnOnce(&'a Runtime) -> Fu,
