genawaiter
genawaiter copied to clipboard
Add a convenience trait for Generator + Iterator?
I found myself writing a generator for an impl IntoIterator type---I had originally used impl Generator before realizing that it wasn't what I wanted because I wanted synchronous usage only. But in theory there's no reason not to expose in my API that the same result could be used as an async Generator. So perhaps there should be a convenience trait that implements both?
trait GenIter : IntoIterator + Generator<Yield = <Self as IntoIterator>::Item, Return = ()> {}
impl<T: IntoIterator + Generator<Yield = <Self as IntoIterator>::Item, Return = ()> GenIter for T {}
This could also include Stream if futures03 is included?
If you want to preserve all capabilities of the original generator, why not just return a concrete Gen?
Because a concrete Gen can't be swapped out as easily. Though I guess if standard generators make it out, I will need to change the interfaces, so maybe it's not worth.
On Thu, 30 Apr 2020 at 19:20, John Simon [email protected] wrote:
If you want to preserve all capabilities of the original generator, why not just return a concrete Gen?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/whatisaphone/genawaiter/issues/23#issuecomment-622170234, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE7AOVMJXPACEBWYRCOR7DLRPIBUHANCNFSM4MRRYDUA .