I think I just described 20 lines of shell haha. But I think there's good value to be had here, which is the important part.
Yeah, but I'm still not seeing any way where we can handle errors inside the None branch. How would the initial example be expressed with these statements? I feel like I'm missing something obvious?
-
-
let node = self.cache.get(key) // Option<K> .ok_or_else(|| self.db.get(key))?; // Result<K, E> can be ?-ed // node is now a K
-
Ahhh, yeah I see where you're going. But believe there's a mistake there. The type returned by the closure will end up being: Result<Result<K, E>, E> Which is incompatible with the return type from `self.cache.get()`. So we'd still need to do `self.db.get(key).unwrap()` :(
- 4 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.