3 ms·
> I still haven’t figured how to map things like cached_results: HashMap<u32, Result<String, Error>> into the fallible function model. In this case, there’s no
by jlokier 7y ago
> I still haven’t figured how to map things like cached_results: HashMap<u32, Result<String, Error>> into the fallible function model. In this case, there’s no function that could be fallible.
Oh you can definitely make a generically cached version of a fallible function, by either:
- Re-throwing the same exception at future lookups, or a clone if preferred (requires storing the exception)
- Treating the exception case as an uncacheable value (always logically consistent with caches that allow items to disappear at any time)