Comments (6)
My original idea for handling this was covered in a remark in Collectable
- in essence, buyer beware - with Collectable
as an unsafe trait. I think that the approach of forcing a Drop
implementation on all Collectable
types is far more elegant, though. Will do.
from dumpster.
@wishawa By the way, do you know any elegant way to extract a TokenStream
for the "default" implementation of Drop
, or do I have to go do that myself?
from dumpster.
A possible wrinkle: in your example solution, MyStructInner
would have to be either !Collectable
or have a manual implementation of Collectable
. An alternate solution would be to make Gc
operations panic if dereferenced during Drop
.
from dumpster.
@wishawa By the way, do you know any elegant way to extract a
TokenStream
for the "default" implementation ofDrop
, or do I have to go do that myself?
The "default" implementation of drop is just
impl Drop for Type {
fn drop(&mut self) {}
}
right?
But if you meant the drop glue, I have no idea. I don't know if it even exists as Rust code (as opposed to being some intermediate representation thing).
from dumpster.
A possible wrinkle: in your example solution,
MyStructInner
would have to be either!Collectable
or have a manual implementation ofCollectable
.
True. I didn't think of that. One fix would be to provide a mostly transparent ManuallyCollectable
type analogous to std::mem::ManuallyDrop
.
An alternate solution would be to make
Gc
operations panic if dereferenced duringDrop
.
This might be the cleanest way to go about it.
An issue is that with careful use of Pin
, it is possible to safely make self-referential types that hold references derefed before the drop. I don't think there is a general fix for this. The good thing is this is almost impossible to unintentionally run in to.
from dumpster.
I've now made it so that Gc::deref
will panic if dereferenced against a value which is currently being dropped.
from dumpster.
Related Issues (10)
- Add Gc::as_ptr by analogy with Rc::as_ptr HOT 1
- Implement PartialEq for Gc HOT 2
- Implement Collectable for UnsafeCell HOT 1
- Just props for the crate, nothing else :) HOT 1
- Serde feature HOT 1
- Consider switching to LGPL HOT 6
- Consider renaming to gcc (garbage collected cell) HOT 1
- Cycles, Gc as Deref during Drop HOT 3
- Map collections HOT 2
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 dumpster.