#async-stream #async #no-alloc #no-std

no-std asynk-strim

Lightweight stream generator library

3 releases

0.1.2 Oct 9, 2024
0.1.1 Oct 8, 2024
0.1.0 Oct 7, 2024

#1005 in Asynchronous

Download history 171/week @ 2024-11-27 37/week @ 2024-12-04 137/week @ 2024-12-11 53/week @ 2024-12-18 107/week @ 2025-01-01 76/week @ 2025-01-08 132/week @ 2025-01-15 33/week @ 2025-01-22 74/week @ 2025-01-29 61/week @ 2025-02-05 79/week @ 2025-02-12 55/week @ 2025-02-19 26/week @ 2025-02-26 9/week @ 2025-03-05 51/week @ 2025-03-12

153 downloads per month

MIT/Apache

19KB
323 lines

asynk-strim

Like async-stream but without macros. Like async-fn-stream but a little more efficient.

Features:

  • macroless API
  • one dependency (besides futures-core which I don't count since it provides the Stream definition)
  • no_std-compatible, zero allocations

⚠ Important

This crate adds a wrapper around the wakers that contains data and pointers needed to yield items. Crates like embassy use a similar approach and will therefore clash with us.

If you run into this issue (which will manifest as a runtime panic), you can use the unwrap_waker function. This function will wrap a future and remove the waker wrapper.

While you can't use the yielder inside the unwrapped future, stuff like embassy should work again.

Example

use futures_lite::stream;
use std::pin::pin;

let stream = pin!(asynk_strim::stream_fn(|mut yielder| async move {
    yielder.yield_item("hello world!").await;
    yielder.yield_item("pretty neato, ain't it?").await;
}));

let mut stream = stream::block_on(stream);
assert_eq!(stream.next(), Some("hello world!"));
assert_eq!(stream.next(), Some("pretty neato, ain't it?"));
assert_eq!(stream.next(), None);

Comparisons

async-stream

In comparison to async-stream we offer the following advantages:

  • no macros
  • slightly faster performance
  • no_std support

async-fn-stream

In comparison to async-stream we offer the following advantages:

  • no allocations
  • slightly faster performance
  • no_std support

Acknowledgements

This crate combines approaches from the following crates:

License

Licensed under tither the MIT or Apache 2.0 license (at your choosing)

Dependencies

~71KB