Skip to content

Stack generator safety suggestion #32

Open
@vlad9486

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions