#future #async #must-use

must_future

A wrapper future marked must_use - mainly to wrap BoxFutures

3 releases

0.1.2 Jun 11, 2020
0.1.1 Apr 10, 2020
0.1.0 Apr 3, 2020

#779 in Asynchronous

Download history 1083/week @ 2024-06-17 1113/week @ 2024-06-24 580/week @ 2024-07-01 919/week @ 2024-07-08 1432/week @ 2024-07-15 614/week @ 2024-07-22 1062/week @ 2024-07-29 1137/week @ 2024-08-05 800/week @ 2024-08-12 966/week @ 2024-08-19 1089/week @ 2024-08-26 826/week @ 2024-09-02 972/week @ 2024-09-09 1153/week @ 2024-09-16 1187/week @ 2024-09-23 771/week @ 2024-09-30

4,123 downloads per month
Used in 73 crates (8 directly)

Apache-2.0

8KB
121 lines

Crates.io Crates.io

must_future

BoxFutures cannot be marked #[must_use] because they are just type definitions. This newtype struct wraps a BoxFuture with something that can be marked #[must_use].

Will Not Compile:

#![deny(unused_must_use)]

use futures::future::FutureExt;

#[tokio::main]
async fn main() {
    fn get_future() -> must_future::MustBoxFuture<'static, ()> {
        async { }.boxed().into()
    }

    get_future(); // unused `must_future::MustBoxFuture` that must be used
}

lib.rs:

BoxFutures cannot be marked #[must_use] because they are just type definitions. This newtype struct wraps a BoxFuture with something that can be marked #[must_use].

Will Not Compile:

#![deny(unused_must_use)]

use futures::future::FutureExt;

#[tokio::main]
async fn main() {
    fn get_future() -> must_future::MustBoxFuture<'static, ()> {
        async { }.boxed().into()
    }

    get_future(); // unused `must_future::MustBoxFuture` that must be used
}

Dependencies

~1MB
~15K SLoC