Currently HashMap::compute requires an FnMut and has no way of persisting state. For example, inserting a V requires cloning if the operation fails and is retried. Internally we memoize consecutive inserts to avoid some of these cases, but that's somewhat of a hack that shouldn't be exposed to users. Instead we might want to provide an on_failure(Operation<V>) hook to allow state to be reset, or maybe even add an Operation::Reset variant. However, this becomes more complicated for updates and I don't want the API to become convoluted, so maybe update_with(key, initial, |val| initial.val = f(val)) or compute_with would be appropriate along side the lower-level compute API.
Currently
HashMap::computerequires anFnMutand has no way of persisting state. For example, inserting aVrequires cloning if the operation fails and is retried. Internally we memoize consecutive inserts to avoid some of these cases, but that's somewhat of a hack that shouldn't be exposed to users. Instead we might want to provide anon_failure(Operation<V>)hook to allow state to be reset, or maybe even add anOperation::Resetvariant. However, this becomes more complicated for updates and I don't want the API to become convoluted, so maybeupdate_with(key, initial, |val| initial.val = f(val))orcompute_withwould be appropriate along side the lower-levelcomputeAPI.