Comments (4)
Thanks a lot for the thorough post! I think this makes sense; the only issue is that I do not want to introduce any unsafe
(which this would do for the manual impls for Send
and Sync
).
We could use &'static T
, but that would require the T: 'static
bound, which isn't great. What about doing PhantomData<fn(T) -> T>
: this makes Id<T>: Send + Sync
and invariant in T
which I think is a good idea.
from idcontain.rs.
Thanks for the swift reply!
I think PhantomData<fn(T) -> T>
may look like a bit of a hack, but I definitely understand trying to avoid unsafe
, and I personally can't think of any more alternatives. It would probably be worth leaving a comment about this in the code, too.
I will test this approach in my code (which requires Id<T>
to be thread safe and without lifetime bounds), verify that it compiles, and report back.
from idcontain.rs.
Another variant, I think, could be PhantomData<Arc<Mutex<*const T>>>
, but it is hardly less hacky than just PhantomData<fn(T) -> T>
, although it could be argued that it conveys the intent better:
Arc
+Mutex
provideSend + Sync
traits*const T
ignores lifetimes.
from idcontain.rs.
I don't think fn(T) -> T
is that hacky; it's what https://doc.rust-lang.org/nomicon/phantom-data.html recommends for non-lifetime bound invariance.
You could argue fn() -> T
is actually how an Id
behaves: it's a function that given an IdSlab
it returns a T
.
from idcontain.rs.
Related Issues (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 idcontain.rs.