Skip to content

Persistent State for HashMap::compute #9

@ibraheemdev

Description

@ibraheemdev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions