must-done

Crates.iomust-done
lib.rsmust-done
version0.1.0
sourcesrc
created_at2023-06-07 05:49:41.120091
updated_at2023-06-07 05:49:41.120091
descriptionAn experimental Future that is guaranteed to be done
homepage
repositoryhttps://github.com/ihciah/must-done
max_upload_size
id884507
size4,065
ihc童鞋@提不起劲 (ihciah)

documentation

README

Must Done

An experimental Future that is guaranteed to be done.

What It Does

In some cases, we need to ensure that the Future is executed and terminated, especially those Futures that have side effects when canceled.

For example, under io_uring, because we cannot ensure that the Future is executed, we have to pass the buffer ownership on the IO interface, which makes the interface very cumbersome to use.

Using this Future wrapper, users can be sure that the Future will be terminated at compile time.

How It Works

Inspired by dtolnay's no-panic, I define a Future Wrapper and placed a Guard in it.

If the Future can not be proven terminated, then the Guard will be dropped, and the drop method of the Guard needs to link to an external library that does not exist, which will trigger an error during the link period; and if the Future must be terminated, the drop implementation will not be used due to dead code elimination.

Some Notes

  1. In order to ensure that dead code elimination can work correctly, a higher opt-level needs to be configured.
  2. When the app panic, the future will be dropped even itself can definitely terminate. So users may set panic = "abort" to avoid future be dropped due to panic possibility.
[profile.dev]
opt-level = 3
panic = "abort"
Commit count: 2

cargo fmt