Skip to main content

async_gen/
lib.rs

1#![doc = include_str!("../README.md")]
2#![warn(missing_docs)]
3
4mod async_coroutine;
5mod async_iter;
6mod types;
7
8pub use futures_core;
9
10pub use async_coroutine::{gen, AsyncGen, Return, Yielder};
11pub use async_iter::{async_iter_from, AsyncIter};
12pub use types::{AsyncGenerator, GeneratorState};
13
14/// A macro for creating generator.
15///
16/// Also see [`gen()`] function for more details.
17///
18/// ## Examples
19///
20/// ```
21/// use std::pin::pin;
22/// use async_gen::{gen, GeneratorState};
23///
24/// # #[nio::main]
25/// # async fn main() {
26/// let gen = gen! {
27///     yield 42;
28///     return "42"
29/// };
30/// let mut g = pin!(gen);
31/// assert_eq!(g.resume().await, GeneratorState::Yielded(42));
32/// assert_eq!(g.resume().await, GeneratorState::Complete("42"));
33/// # }
34/// ```
35#[macro_export]
36macro_rules! gen {
37    ($($tt:tt)*) => {
38        $crate::__private::gen_inner!(($crate) $($tt)*)
39    }
40}
41
42/// Asynchronous stream
43#[macro_export]
44macro_rules! stream {
45    ($($tt:tt)*) => {
46        $crate::__private::gen_inner!(($crate) $($tt)*).into_async_iter()
47    }
48}
49
50#[doc(hidden)]
51pub mod __private {
52    pub use async_gen_macros::gen_inner;
53}