gen-iter
gen-iter copied to clipboard
add struct `GenIterReturn` and macro `gen_iter_return!` to iterate over a generator and get the return value
add struct GenIterReturn
and macro gen_iter_return!
to iterate over a generator and get the return value
[GenIterReturn
] can be converted from a Generator<()>
,
&mut GenIterReturn<G>
can be used as iterator.
The return value of the generator can be got after the iterator is exhausted.
Differences with GenIter<G>
:
- able to get return value of a generator
- safe to call
next()
after generator is done without panic - maybe less efficient than
GenIter<G>
[gen_iter_return!
] helps to create a [GenIterReturn
].
#![feature(generators)]
use gen_iter::gen_iter_return;
let mut g = gen_iter_return!({
yield 1;
yield 2;
return "done";
});
for y in &mut g {
println!("yield {}", y);
}
println!("generator is_done={}", g.is_done()); // true
println!("generator returns {}", g.return_or_self().ok().unwrap()); // "done"
can you add a changelog entry? ill push a new release soon
- made the crate no_std compatible by adding
#![no_std]
- added struct
GenIterReturn
and macrogen_iter_return!
to iterate over a generator and get the return value
thanks!
Any update on this? It would be nice to have this :)
forgot to actually merge this nine months ago
*crawls back into my hole*