-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add map-like methods to AtomicRef(Mut) which work with new objects rather than references #11
Comments
I successfully implemented all the functionality described above. Please let me know if you are interested in a PR. |
Thanks, and sorry for the lag. So the basic issue here is that you want to use a tuple of borrows, but the tuple is technically not a borrowed type, right? My intuition is that the duplication across {,Owned}AtomicRef{,Mut} would make the code more complex. So unless we find an elegant way to generalize across the permutations, I'm hesitant to take such a patch absent strong demand from multiple consumers. However, I'll leave this issue open so that others can comment if they run into the same issue. |
Yes that's exactly it. |
I have a similar need. I have a type such as |
For anybody else who needs it, I was able to accomplish what I needed using the |
Note that there is some subtle behavior that you need to be aware of to do this soundly. References passed as function parameters (either directly or included in a type) are treated as if they could be used up until the end of that function even if they aren't used after a certain point (or to put it another way they are expected to not be aliased incorrectly for the entirety of the function). For an example of how this manifests see #18 To disable this you can wrap the reference/type containing the reference in For details on why this exists: https://perso.crans.org/vanille/treebor/protectors.html. |
Big thanks for pointing that out to me! That's a very easy foot-gun to miss. I'll look into a PR for |
Having
map
methods for reference types which can only work with sub-borrows of the original object is a bit too restrictive in my opinion, and it doesn't allow certain patterns as the one presented bellow. My solution is to add an additional method to all reference types,map_into
, which can create entirely new objects with the same lifetime as the original. This change requires adding additional reference types that holdT
's, instead of&(mut) T
's, which I've calledOwnedAtomicRef
andOwnedAtomicRefMut
.Here is the problem that adding
map_into
would solveThe text was updated successfully, but these errors were encountered: