Generators are still unstable, and generating streams requires complicated ownership handling, so this crate aims to enable ad-hoc generation of streams.
Current async implementations attempt to provide yield
syntax via macros,
but this is not transparent to IDEs at the time of this library's creation,
so gen_z
attempts to work in a way that IDEs understand.
gen_z // => Result is a futures::stream::Stream<Item = T>
Send
is required forStream::Item
.- The stream is
Send
if the provided future is alsoSend
.
- The stream is
Sync
is available ifStream::Item
and the future are bothSync
.- The generator only requires
FnOnce
, so it may close over mutable references. - Infinite streams can be generated by looping within the provided future
- Generators are infallible; the given future must return
()
, run forever, or panic.- To use
Result<_, _>
, create an inner-future which returnsResult
and convert anErr
return to a type compatible withStream::Item
.TryStream
compatibility can be achieved by setting theStream::Item
type toResult<T, TErr>
.
- To use