Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename Generator to Coroutine #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
doc: compare to gen block in edition2024
  • Loading branch information
viruscamp committed Sep 14, 2024
commit 9b268bad2d38efe2e31628af5387dfbdba4d00dc
40 changes: 38 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! [`GenIter`] converts a [`Coroutine<(), Return=()>`](core::ops::Coroutine) into an iterator over the
//! yielded type of the coroutine. The return type of the coroutine needs to be `()`.
//!
//! [`gen_iter!`] helps to create a [`GenIter`]
//! ### [`gen_iter!`] helps to create a [`GenIter`]
//!
//! ```
//! #![feature(coroutines)]
Expand All @@ -35,13 +35,47 @@
//! println!("{}", elem);
//! }
//! ```
//! ### compare to gen block in edition2024
//!
//! <div style="display:flex; gap: 2rem">
//! <div>
//!
//! ```ignore
//! # #![feature(coroutines)]
//! #![feature(gen_blocks)]
//! let gen1 = gen {
//! yield 1;
//! yield 2;
//! };
//! for x in gen1 {
//! println!("{x}");
//! }
//! ```
//!
//! </div>
//! <div>
//!
//! ```
//! # #![feature(coroutines)]
//! use gen_iter::gen_iter;
//! let gen1 = gen_iter!({
//! yield 1;
//! yield 2;
//! });
//! for x in gen1 {
//! println!("{x}");
//! }
//! ```
//!
//! </div>
//! </div>
//!
//! ## [`GenIterReturn`] and [`gen_iter_return!`]
//! [`GenIterReturn`] can be converted from a [`Coroutine<()>`](core::ops::Coroutine),
//! `&mut GenIterReturn<G>` can be used as iterator.
//! The return value of the coroutine can be got after the iterator is exhausted.
//!
//! [`gen_iter_return!`] helps to create a [`GenIterReturn`].
//! ### [`gen_iter_return!`] helps to create a [`GenIterReturn`].
//!
//! ```
//! #![feature(coroutines)]
Expand All @@ -62,6 +96,8 @@
//! ```
//!
//! ## support immovable coroutine (self-referenced)
//! The created `GenIter<_>` cannot be moved out of current stack frame,
//! cause the underlying coroutine is pinned in stack.
//! ```
//! #![feature(coroutines)]
//!
Expand Down