Announcing π async-dropper: the least worst AsyncDrop implementation you've seen so far, probably
TL;DR - π async-dropper on crates.io
Hey all,
I've worked on code in the past where I really wanted to do async stuff in Drop. Like many people I searched around and found this StackOverflow post, and realized that AsyncDrop just isn't a thing in Rust yet (and may never be).
Great libraries offer some alternatives like tokio's kill_on_drop, so depending on the lib you're using it might be a solved problem.
For when it is a problem, I wrote a small wrapper around the stuff in the SO post, but was somewhat unsatisfied with the wrapper struct approach (though it works fantastically well!) -- so I explored a different direction -- a derive macro that uses a notion of equality (Default + PartialEq + Eq) to tell when something should have async drop performed or not -- this means that there's no need to wrap things in structs (but there IS a need to make sure you have cheap default states!).
Check it out here:
Excited to hear any feedback/suggestions for improvements! If you think the idea is absolutely asinine/a fools errand I'd love to hear that too (and any suggestions for what to do instead).