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
However, if I try to add explicit lifetimes to the Callback trait, I get compilation error:
error[E0309]: the parameter type `State` may not live long enough
--> src/storage.rs:252:33
|
250 | impl<'state, State, F, Fut> Callback<'state, State> for F
| ------ the parameter type `State` must be valid for the lifetime `'state` as defined here...
251 | where
252 | F: Fn(&'state mut State) -> Fut,
| ^^^ ...so that the reference type `&'state mut State` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound
|
250 | impl<'state, State: 'state, F, Fut> Callback<'state, State> for F
| ++++++++
But if I fix it according to the suggestion, I get the following error:
error[E0310]: the parameter type `State` may not live long enough
--> src/storage.rs:270:5
|
270 | aaa(state, &callback).await;
| ^^^^^^^^^^^^^^^^^^^^^
| |
| the parameter type `State` must be valid for the static lifetime...
| ...so that the type `State` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound
|
268 | pub async fn bbb<State: 'static, Cb>(state: &mut State) {
| +++++++++
error[E0310]: the parameter type `State` may not live long enough
--> src/storage.rs:270:27
|
270 | aaa(state, &callback).await;
| ^^^^^
| |
| the parameter type `State` must be valid for the static lifetime...
| ...so that the type `State` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound
|
268 | pub async fn bbb<State: 'static, Cb>(state: &mut State) {
| +++++++++
Compiler version 1.81.0.
I am writing an asynchronous function that takes asynchronous callback, I managed to write it so that it compiles:
However, if I try to add explicit lifetimes to the Callback trait, I get compilation error:
for the following code:
But if I fix it according to the suggestion, I get the following error:
for the code
I thing something is not correct about treating explicit lifetimes by the compiler, or I added the lifetimes incorrectly.
Please help.
The text was updated successfully, but these errors were encountered: