genawaiter icon indicating copy to clipboard operation
genawaiter copied to clipboard

Add a convenience trait for Generator + Iterator?

Open alercah opened this issue 5 years ago • 3 comments

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 {}

alercah avatar Apr 27 '20 03:04 alercah

This could also include Stream if futures03 is included?

alercah avatar Apr 27 '20 03:04 alercah

If you want to preserve all capabilities of the original generator, why not just return a concrete Gen?

whatisaphone avatar Apr 30 '20 23:04 whatisaphone

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 .

alercah avatar May 03 '20 07:05 alercah