libcore: Add iter::from_generator which is like iter::from_fn, but for coroutines instead of functions#96298
Conversation
|
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
|
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
It might be reasonable to also add a version that accepts a Pin<&mut G>, since that way immovable generators can be used as well.
There was a problem hiding this comment.
I'm intrigued if there's a way to support both from the same function (is a Pin<&mut Generator<Return = ()>>: Generator<Return = ()> + Unpin?)
Either way, I think we can add that on a follow up PR.
There was a problem hiding this comment.
I'm not quite sure what you mean. Right now there isn't an easy way to accept both direct mutable references and pinned ones, but that would be a lovely thing.
There was a problem hiding this comment.
I'm just wondering what changes we could make so that Pin<&mut Generator<Return = ()>> can satisfy Generator<Return = ()> + Unpin, making this function work for both versions.
There was a problem hiding this comment.
Oh! Now I understand, I think. That's actually a good question...
There was a problem hiding this comment.
Pretty sure that's already the case for Future (yup) so it shouldn't be hard to do it for Generator.
|
The main cases I've seen of this pattern in the wild have been via the propane crate which mostly provides exactly what this does except via a macro instead. Not sure if there are more recent uses that folks can point to, though. |
This comment was marked as resolved.
This comment was marked as resolved.
…t for coroutines instead of functions
|
@bors r=estebank |
|
📌 Commit 5bf23f6 has been approved by |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (4f68efa): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
An equally useful little helper.
I didn't follow any of the async-wg work, so I don't know why something like this wasn't added before.