-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Cloneable generators #57972
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
Comments
The } |
I think I can say fairly confidently that It looks like supporting this for self-referential generators would run into #63818 too, so limiting it to movable generators seems like the only option. A simplification would be to first limit it to |
Related: #95360 |
Looks like #95360 fully covers this. |
There was some discussion on Discord about whether generators can be cloned. It seems to me that non-self-referential generators can be trivially cloneable if everything in their environment implements clone (including both upvars and saved state, the implementation would be non-trivial as it would have to check the current state to know which fields need cloning, but that's basically like the generated
Drop
implementation).I don't see any way that self-referential generators could be cloneable, if there were some sort of
fn clone_into(&self, place: Pin<*mut Self>)
operation they could potentially support that via re-writing the self-references, but that doesn't exist yet as far as I know. You can clone them before starting by using something likeimpl (FnOnce() -> impl Generator) + Clone
instead of taking the generator directly.The text was updated successfully, but these errors were encountered: