Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement an async Drop in Rust?

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.

like image 551
Matt Joiner Avatar asked Jan 17 '20 06:01

Matt Joiner


1 Answers

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:

  • How do I synchronously return a value calculated in an asynchronous Future in stable Rust?
like image 54
Shepmaster Avatar answered Oct 03 '22 08:10

Shepmaster