Closed GlenDC closed 9 months ago
If there's interest for this I'm willing to contribute this, would just need to know what the preferred API would be in that case...
Hm, I'm sympathetic to the usage pain, but I'm apprehensive about making the Extensions
type much more like HashMap
, such as with an Entry type. Possibly get_or_...
methods would be sufficient?
Yes. That’s indeed what I had in mind. How would you name these methods exactly? So i can open a PR or would this need more discussion first?
There’s no rush btw. I scratched the original use cases for this, as it seems to lead to worse design. So far I haven’t found a legit new use case for it where it would unblock something or change things for the better.
so unless there are others that want this or you yourself think this is useful I’m going to not implement this until also voted/requested by you or others.
I'd appreciate get_or_...
methods as well. I can make a PR if you're interested @seanmonstar
Sure!
Currently it is not possible to use the https://doc.rust-lang.org/stable/std/collections/hash_map/enum.Entry.html#method.or_insert_with for the Extensions, despite it being a hashmap.
Granted it's an edge case and also maybe the entire Entry API is a bit over kill. But at the very least would be nice if one could do
get_or_else(..fn)
andget_mut_or_else(..fn)
.At the moment that would require first using a
get()
and then aninsert()
etc... Awkward and can give also awkward lifetime situations.