Cloneable generators #57972
Labels
A-coroutines
Area: Coroutines
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
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: