actix / actix-extras

A collection of additional crates supporting the actix and actix-web frameworks.
https://actix.rs
Apache License 2.0
787 stars 206 forks source link

implement contains_key, update, update_or #459

Open keithamus opened 3 months ago

keithamus commented 3 months ago

PR Type

Feature

PR Checklist

Overview

It's quite common to want to update a value based on its existence in a map, and its current value. The typical case being incrementing counters. Right now this is a bit cumbersome, as you have to do a handle error states for serialize/deserialize and then an insert/update.

This PR adds contains_key, update, and update_or methods.

My core use case is probably update_or, but the other two feel like a natural fit in terms of ergonomics, and are kind of required to make update_or work.

I come with an open mind and I'm happy to hear feedback on the API design, or otherwise if you don't think this is a good fit feel free to close the PR.

keithamus commented 2 months ago

Thoughts on this one?