Please take a look at my code and suggest a possible fix:
use std::future::Future;
pub async fn bar() {
let mut x = 0u8;
foo(&mut x, |x| baz(x)).await;
}
pub async fn baz(x: &mut u8) {
*x += 1;
}
pub async fn foo<'a, F, T>(x: &'a mut u8, f: F)
where
F: Fn(&'a mut u8) -> T,
T: Future<Output = ()> + 'a,
{
loop {
f(x).await;
}
}
Why does x remain borrowed after await
? What is a proper fix?