Closed Sushisource closed 4 years ago
Thanks!
I think retain
should let you do what you want, no? I just pushed (and will soon release) a change to retain
which lets you give an FnMut
closure, which should in turn make this a decent amount easier. Note that retain
is (now, and should have been in the past) unsafe
; you need to make sure that it retains the same elements from the value-set both times it is called!
I'm going to close this as I believe retain
does what you want.
This definitely relates to https://github.com/jonhoo/rust-evmap/issues/29
So, all that understood, I'm wondering it there's a particular trick for this usecase that might stay efficient (namely, I want my value sets/vecs to always be N or fewer elements, a sort of LRU cache)? Intuitively it seems this could be implemented in terms of
retain
and keeping a tiny bit of extra metadata on each item.Alternatively, I had started implementing this with a
get_and
, copy, and thenupdate
with the new values. Only to realizeupdate
doesn't swap out the entire value set, but rather replaces the new set with a one-value set. Adding areplace
method that allows you to provide an entire set/vec as the second param would be desirable. I think theupdate
method is a bit unintutive in that respect.Really like the library! Thanks for your work!