Comments (7)
I successfully implemented all the functionality described above. Please let me know if you are interested in a PR.
from atomic_refcell.
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.
from atomic_refcell.
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?
Yes that's exactly it.
from atomic_refcell.
I have a similar need.
I have a type such as AtomicRef<UntypedStorage>
, and there's a method to convert a borrow of &'a UntypedStorage
to a TypedStorage<'a, T>
, but I couldn't do that in AtomicRef.map
because TypedStorage
is actually an owned type, with the same lifetime as the &UntypedStorage
reference, not a reference to a field of UntypedStorage
.
from atomic_refcell.
For anybody else who needs it, I was able to accomplish what I needed using the atomicell
crate. It has an unsafe method RefMut::into_split()
that allows you to get access to the borrow guard and the reference separately, at which point, you must ensure that the reference is never accessed after the borrow guard is dropped, but you can create your own MappedRefMut
or whatever you need for your use-case using the guard and the reference.
from atomic_refcell.
at which point, you must ensure that the reference is never accessed after the borrow guard is dropped, but you can create your own
MappedRefMut
or whatever you need for your use-case using the guard and the reference.
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 MaybeDangling
from https://docs.rs/maybe-dangling.
For details on why this exists: https://perso.crans.org/vanille/treebor/protectors.html.
from atomic_refcell.
Big thanks for pointing that out to me! That's a very easy foot-gun to miss. I'll look into a PR for atomicell
.
from atomic_refcell.
Related Issues (10)
- Remove Sync constraints ? HOT 1
- Bounds for `AtomicRefCell<T>: Send` are unnecessarily restrictive HOT 1
- #[cfg(feature = "debug_atomic_refcell")] ? HOT 2
- License HOT 6
- Improve mapping features HOT 1
- Create a Security Policy
- AtomicRefMut is not Sync nor Send in async block
- AtomicWeakRef
- Perfomance? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atomic_refcell.