1
2
3
4
5
6
7
8
9
10
11
12
13
use std::future::Future;
use std::ptr;
pub async fn replace_with_async<'a, R, F: Future<Output = R> + 'a, C: FnOnce(R) -> F>(
dest: &mut R,
fun: C,
) {
unsafe {
let old = ptr::read(dest);
let new = fun(old).await;
ptr::write(dest, new);
}
}