#async #futures #no-std

no-std futures-micro

Zero dependency, no_std compatible async prelude

6 releases (3 breaking)

0.4.0 Nov 6, 2020
0.3.1 Aug 23, 2020
0.2.0 Aug 13, 2020
0.1.1 Aug 11, 2020

#76 in Asynchronous

Download history 176/week @ 2020-11-02 227/week @ 2020-11-09 136/week @ 2020-11-16 250/week @ 2020-11-23 161/week @ 2020-11-30 169/week @ 2020-12-07 137/week @ 2020-12-14 139/week @ 2020-12-21 117/week @ 2020-12-28 175/week @ 2021-01-04 299/week @ 2021-01-11 322/week @ 2021-01-18 233/week @ 2021-01-25 181/week @ 2021-02-01 172/week @ 2021-02-08 176/week @ 2021-02-15

474 downloads per month
Used in 15 crates (3 directly)

Apache-2.0 WITH LLVM-exception

15KB
235 lines

futures-micro

License Package Documentation

To futures-lite as futures-lite is to futures: smaller.

Features:

  • Fun tools to write everything as async fns.

  • Tiny, no dependencies.

  • 100% no_std support, no heap allocation required!

  • Complete stable compiler support - Uses no nightly features!

  • Bootstrap tools:

    • poll_fn - wrap a function into a future.
    • dropped: poll_state - wrap a function and some state into a future.
      /// outdated
      poll_state(INITIAL, |state, ctx| {...}).await
      
      /// replacement (NOTE: `*state` should be replaced by `state`)
      let mut state = INITIAL;
      poll_fn(move |ctx| { ... }).await
      
    • pin!() - pin a value to the stack.
  • Futures interface subversion (poll interface from async fns):

    • waker() to get the current waker.
    • sleep() to wait until you are woken.
    • next_poll() - polls a future once, returning it for reuse if pending.
  • Common stuff:

    • dropped: pending() - never completes.
      /// outdated
      pending()
      /// replacement
      poll_fn(|_| ::core::task::Poll::Pending)
      
    • dropped: ready() - completes on first poll.
      /// outdated
      ready(x)
      /// replacement
      async { x }
      
    • yield_once() - lets some other futures do some work .
    • or() - return the result of the first future to complete.
    • or!() - or(), but varargs.
    • zip() - return the result of both futures when they both complete.
    • zip!() - zip(), but varargs.
    • ready!() - unwraps a ready value or returns pending.

Status

Beta? The API we have here seems pretty reasonable now.

If there's something you're missing, you may be looking for futures-lite.

Soundness

This crate uses unsafe for pin projection. We believe the code to be correct, but we'd welcome more eyes on it.

Yes, we could get rid of them with pin-project-lite, but it's just hiding the mess and then we couldn't claim zero dependencies.

Copyright and License

Copyright (c) 2020 James Laver, Matthieu le Brazidec, Stjepan Glavina, Erik Zscheile, futures-micro contributors, futures-lite contributors

Licensed under Apache License, Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0), with LLVM Exceptions (https://spdx.org/licenses/LLVM-exception.html).

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

No runtime deps