You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
--> src/main.rs:20:56
|
20 | block_on_stream(stream::empty().map(move |_: ()| f.make::<bool>()));
| ^^^^
|
note: first, the lifetime cannot outlive the lifetime '_ as defined on the body at 20:41...
--> src/main.rs:20:41
|
20 | block_on_stream(stream::empty().map(move |_: ()| f.make::<bool>()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `f`
--> src/main.rs:20:54
|
20 | block_on_stream(stream::empty().map(move |_: ()| f.make::<bool>()));
| ^
note: but, the lifetime must be valid for the method call at 20:21...
--> src/main.rs:20:21
|
20 | block_on_stream(stream::empty().map(move |_: ()| f.make::<bool>()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that a type/lifetime parameter is in scope here
--> src/main.rs:20:21
|
20 | block_on_stream(stream::empty().map(move |_: ()| f.make::<bool>()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
error: could not compile `stream-async-trait`.
I've tried various permutations with 'async_trait and 'a leading to similar results.
I'm trying to figure out if what I'm attempting is supported and I'm just missing something?
Perhaps this is related to #8 (I don't have quite a strong enough handle on Futures/lifetimes to tell for sure)?
The text was updated successfully, but these errors were encountered:
This signature is not expressible using async fn in Rust (whether or not async_trait is involved). An async fn in Rust does not begin executing until the first time it is awaited, which means every input lifetime is necessarily captured by the future.
So it sounds like while it would be technically possible for async_trait to support this (because of its current implementation), such support wouldn't really be in keeping with the intent of this crate (which I assume is to act just as as closely to how async trait members will work if they're ever implemented upstream)?
If that's true, I think this issue should be closed, thank you.
I realize this is now just a general async rust question, so of course feel free to just redirect me to StackOverflow :), but I was wondering if there was a common/recommended pattern to accomplish what I'm after. I'm thinking that I'll do the following and just accept that LocalBoxFuture will be with me for the duration:
fnmake<'a,T:Default + 'a>(&self) -> LocalBoxFuture<'a,T>{// do all work with `self` hereBox::pin(async{// use nice `?` error-handling hereT::default()})}
I have a
Stream
that needs to run aFuture
from a trait method on each iteration. I've managed to get it to work using aLocaslBoxFuture
:However, I haven't been able to figure out how to accomplish the same with
async_trait
. For example, attempting the following fails:With error:
I've tried various permutations with
'async_trait
and'a
leading to similar results.I'm trying to figure out if what I'm attempting is supported and I'm just missing something?
Perhaps this is related to #8 (I don't have quite a strong enough handle on
Futures
/lifetimes to tell for sure)?The text was updated successfully, but these errors were encountered: