I have an async fn
that returns a type, and want to implement Drop
on that type that calls another async
function. It's not clear how to do this, and I can't find anything in the docs. The most illuminating article I found is Asynchronous Destructors by withoutboats, but I don't really understand the reasoning, or where this feature is at.
How do I implement an async Drop in Rust?
Asked Answered
The point of the article is precisely to said that it's not currently possible. And propose a possible solution, but AFAIK it doesn't exist yet. –
Shrivel
It's not clear how to do this, and I can't find anything in the docs
That's because it's not possible; there is no "async Drop
". Drop
must be synchronous.
See also:
Since this question was originally answered, there has been movement in the repo, and there is now a (nightly-only) AsyncDrop
trait that those interested in such things can use. It doesn't define an async fn you can implement (because we don't have async traits yet), but it gives you a pinned self
you can fiddle with to call into your executor to do the work.
I guess when this is stabilized, this can be marked answer. –
Hexagonal
© 2022 - 2024 — McMap. All rights reserved.