#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

#785 in Asynchronous

Download history 654/week @ 2024-07-21 1040/week @ 2024-07-28 1117/week @ 2024-08-04 875/week @ 2024-08-11 971/week @ 2024-08-18 1003/week @ 2024-08-25 897/week @ 2024-09-01 978/week @ 2024-09-08 1153/week @ 2024-09-15 1139/week @ 2024-09-22 805/week @ 2024-09-29 619/week @ 2024-10-06 805/week @ 2024-10-13 732/week @ 2024-10-20 943/week @ 2024-10-27 776/week @ 2024-11-03

3,276 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