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

Stack generator safety suggestion #32

Open
vlad9486 opened this issue Sep 2, 2021 · 0 comments
Open

Stack generator safety suggestion #32

vlad9486 opened this issue Sep 2, 2021 · 0 comments

Comments

@vlad9486
Copy link

vlad9486 commented Sep 2, 2021

I think it is possible to make stack generator safe. The Co object is not Clone, therefore the only possibility to outlive the Gen is to return it from the coroutine, am I right? It is even impossible to yield it. Type system can require the coroutine return the Co object along with its return value.

pub struct Gen<'s, Y, R, F: Future> {

will be

pub struct Gen<'s, Y, R, Ret, F: Future<Output = (Co<'s, Y, R>, Ret)>> {

and

    pub fn resume_with(&mut self, arg: R) -> GeneratorState<Y, F::Output> {

will be

    pub fn resume_with(&mut self, arg: R) -> GeneratorState<Y, Ret> {

The user is forced to return the Co, and they cannot clone it, so it will be the same Co, and Ret cannot contain one more.

peterhj pushed a commit to peterhj/genawaiter that referenced this issue Aug 31, 2023
that Co could be returned from stack::Gen, so we force the async
producer to stack::Gen to be a return type constructed solely by
consumption of Co.

(This implements the suggestion of vlad9486 in whatisaphone#32.)
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

1 participant