-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Have a way to disable Drop #523
Comments
Unfortunately linear types don't play well with unwinding. That is, at any time something can panic and scoop up your related-ish: #197 |
If I understand correctly, it seems like |
Another application could be things such as files and database connections. Closing a file or database connection on drop is dangerous, because closing can fail (device may no longer be available but there might still be unwritten data in a buffer). The only way for |
Since this essentially requests linear types, I'm closing in favor of #814. |
It would be great if there was a way to disable
Drop
for a type. What this would mean is that a value that can't dropped has to be moved or have data moved out of it to destroy it.One use case for this is avoiding leaking threads by having threads that require a handle to the thread to be kept around. Basically, I'd like to write some code like this:
The problem with writing this is that, if
Thread
can be dropped it defeats the whole point of the type. But if I implementDrop
manually it's not possible to write thejoin
method because it movesself
. In today's Rust the closest thing I can do is putrx.recv()
indrop()
which means thatdrop()
blocks (ew!), and means it's not possible to return a value from the thread.How I see
#[no_drop]
working is just that the following code becomes illegal:This is just one example of an application of linear types but I'm sure there are others. For example, a type for serious errors that can't be ignored and which the programmer is forced to handle. Sort of like the lint we have now for
Result
values but which is enforced.The text was updated successfully, but these errors were encountered: