How do I write the following function using unwrap_or_else ?
// This works
pub async fn from_cache_or_synced () -> Result<Self, Error> {
match Self::from_cache() {
Ok(redorg) => Ok(redorg), // I don't like this
Err(_) => {
let mut redorg_init = Self::new();
redorg_init.sync().await;
Ok(redorg_init)
}
}
}
This does not work and I don't understand why?
pub async fn from_cache_or_synced2 () -> Result<Self, Error> {
let redorg = Self::from_cache().unwrap_or_else( |_| async {
let mut redorg_init = Self::new();
redorg_init.sync().await;
redorg_init
});
Ok(redorg)
}
It says expected struct Redorg, found opaque type Future.