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

Add a convenience trait for Generator + Iterator? #23

Open
alercah opened this issue Apr 27, 2020 · 3 comments
Open

Add a convenience trait for Generator + Iterator? #23

alercah opened this issue Apr 27, 2020 · 3 comments

Comments

@alercah
Copy link

alercah commented Apr 27, 2020

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
Copy link
Author

alercah commented Apr 27, 2020

This could also include Stream if futures03 is included?

@whatisaphone
Copy link
Owner

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

@alercah
Copy link
Author

alercah commented May 3, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants